Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Implementing Model-View-Presenter in ASP.NET

, 17 Nov 2007
Three implementations of Model-View-Presenter in ASP.NET 2.0.
MVPSampleApp.zip
MVP.SampleApp
Lib
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
MySql.Data.dll
nunit.framework.dll
Rhino.Mocks.dll
Model
Data
Interfaces
Properties
Presentation
Presentation.Tests
Properties
Interfaces
Properties
SubSonic
ActiveRecord
Builder
CodeGeneration
Templates
CodeLanguage
Configuration
Controls
Calendar
lang
skin
active-bg.gif
calendar.gif
dark-bg.gif
hover-bg.gif
menuarrow.gif
normal-bg.gif
rowhover-bg.gif
status-bg.gif
title-bg.gif
today-bg.gif
Resources
DataProviders
Properties
Sql Tools
SubSonic.snk
Sugar
WebApp
App_Data
Views
SQL2000SampleDb.zip
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

//Generated on 11/6/2007 2:44:49 PM by Alex

namespace Model.Data.Northwind
{
    /// <summary>
    /// Controller class for Employees
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class EmployeeController
    {
        // Preload our schema..
        Employee thisSchemaLoad = new Employee();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public EmployeeCollection FetchAll()
        {
            EmployeeCollection coll = new EmployeeCollection();
            Query qry = new Query(Employee.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public EmployeeCollection FetchByID(object EmployeeID)
        {
            EmployeeCollection coll = new EmployeeCollection().Where("EmployeeID", EmployeeID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public EmployeeCollection FetchByQuery(Query qry)
        {
            EmployeeCollection coll = new EmployeeCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object EmployeeID)
        {
            return (Employee.Delete(EmployeeID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object EmployeeID)
        {
            return (Employee.Destroy(EmployeeID) == 1);
        }

        
        
        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(int EmployeeID)
        {
            Query qry = new Query(Employee.Schema);
            qry.QueryType = QueryType.Delete;
            qry.AddWhere("EmployeeID", EmployeeID);
            qry.Execute();
            return (true);
        }
        
       
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string LastName,string FirstName,string Title,string TitleOfCourtesy,DateTime? BirthDate,DateTime? HireDate,string Address,string City,string Region,string PostalCode,string Country,string HomePhone,string Extension,byte[] Photo,string Notes,int? ReportsTo,string PhotoPath)
	    {
		    Employee item = new Employee();
		    
            item.LastName = LastName;
            
            item.FirstName = FirstName;
            
            item.Title = Title;
            
            item.TitleOfCourtesy = TitleOfCourtesy;
            
            item.BirthDate = BirthDate;
            
            item.HireDate = HireDate;
            
            item.Address = Address;
            
            item.City = City;
            
            item.Region = Region;
            
            item.PostalCode = PostalCode;
            
            item.Country = Country;
            
            item.HomePhone = HomePhone;
            
            item.Extension = Extension;
            
            item.Photo = Photo;
            
            item.Notes = Notes;
            
            item.ReportsTo = ReportsTo;
            
            item.PhotoPath = PhotoPath;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int EmployeeID,string LastName,string FirstName,string Title,string TitleOfCourtesy,DateTime? BirthDate,DateTime? HireDate,string Address,string City,string Region,string PostalCode,string Country,string HomePhone,string Extension,byte[] Photo,string Notes,int? ReportsTo,string PhotoPath)
	    {
		    Employee item = new Employee();
		    
				item.EmployeeID = EmployeeID;
				
				item.LastName = LastName;
				
				item.FirstName = FirstName;
				
				item.Title = Title;
				
				item.TitleOfCourtesy = TitleOfCourtesy;
				
				item.BirthDate = BirthDate;
				
				item.HireDate = HireDate;
				
				item.Address = Address;
				
				item.City = City;
				
				item.Region = Region;
				
				item.PostalCode = PostalCode;
				
				item.Country = Country;
				
				item.HomePhone = HomePhone;
				
				item.Extension = Extension;
				
				item.Photo = Photo;
				
				item.Notes = Notes;
				
				item.ReportsTo = ReportsTo;
				
				item.PhotoPath = PhotoPath;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alex Mueller
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 17 Nov 2007
Article Copyright 2007 by Alex Mueller
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid