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 CPOL
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
SQL2000SampleDb.msi
using System;
using System.Collections.Generic;
using System.Data;

namespace SubSonic
{

    [Serializable]
    public class ActiveList<ItemType, ListType> : AbstractList<ItemType, ListType> 
        where ItemType : ActiveRecord<ItemType>, new()
        where ListType : AbstractList<ItemType, ListType>, new()
    {
        public ActiveList(){}

        public ActiveRecord<ItemType> Find(object primaryKeyValue) {
            ActiveRecord<ItemType> result = null;
            foreach (ItemType item in this) {
                if (item.GetPrimaryKeyValue().Equals(primaryKeyValue)) {
                    result = item;
                }
            }
            return result;
        }

        /// <summary>
        /// Creates and loads the collection, leaving the IDataReader open.
        /// </summary>
        /// <param name="rdr"></param>
        public ActiveList(IDataReader rdr) 
        {
            Load(rdr);
        }

        /// <summary>
        /// Creates and loads the collection, with option to set IDataReader close behavior.
        /// </summary>
        /// <param name="rdr"></param>
        /// <param name="closeReader"></param>
        public ActiveList(IDataReader rdr, bool closeReader) 
        {
            Load(rdr);
            if (closeReader)
            {
                rdr.Close();
            }
        }

        /// <summary>
        /// Saves all the records in a collection to the DB
        /// </summary>
        public void SaveAll(string userName) {
            foreach (ItemType item in this) {
                item.Save(userName);
            }
        }
        /// <summary>
        /// Saves all the records in a collection to the DB
        /// </summary>
        public void SaveAll(Guid userID) {
            foreach (ItemType item in this) {
                item.Save(userID);
            }
        }
        /// <summary>
        /// Saves all the records in a collection to the DB
        /// </summary>
        public void SaveAll() {
            foreach (ItemType item in this) {
                item.Save();
            }
        }

        /// <summary>
        /// Uses a transaction to quickly saves all the records in a collection to the DB
        /// The primary keys of any new records are not updated in the collection
        /// You must reload the collection to get the latest data
        /// </summary>
        public void BatchSave(string userName)
        {
            QueryCommandCollection commands = new QueryCommandCollection();
            foreach (ItemType item in this)
            {
                QueryCommand cmd = item.GetSaveCommand(userName);
                if (cmd != null)
                    commands.Add(cmd);
            }

            DataService.ExecuteTransaction(commands);
        }

        public void BatchSave()
        {
            BatchSave(string.Empty);
        }
        public void BatchSave(Guid userID)
        {
            BatchSave(userID.ToString());
        }
        public void BatchSave(int userID)
        {
            BatchSave(userID.ToString());
        }

        /// <summary>
        /// Saves all the records in a collection to the DB
        /// </summary>
        public void SaveAll(int userId) {
            foreach (ItemType item in this) {
                item.Save(userId);
            }
        }

        public ListType Clone()
        {
            ListType coll = new ListType();
            foreach(ItemType item in this)
            {
                ItemType newItem = item.Clone();
                coll.Add(newItem);
            }
            return coll;
        }
    }
}

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 | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 17 Nov 2007
Article Copyright 2007 by Alex Mueller
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid