Click here to Skip to main content
15,885,914 members
Articles / Web Development / ASP.NET

Open Source Extensible Enterprise n-tier Application Framework with Multilayered Architecture

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
3 Dec 2010MIT3 min read 36.9K   770   41  
Xenta architecture overview
using System.Data;
using System.Data.Common;
using SiberTek.Xenta.Data.Entities;
using SiberTek.Xenta.Data.Entities.Collections;
using SiberTek.Xenta.Data.Utils;
using System;

namespace SiberTek.Xenta.Data.Providers
{
    public class ForumBanDataProvider : DataProviderBase, IForumBanDataProvider
    {
        #region Methods
        public bool InsertForumBan(int userID, string description, DateTime createdOn, DateTime? expiredOn, DateTime updatedOn, out int banID)
        {
            bool res = false;
            banID = 0;

            using(DbCommand cmd = DataBase.GetStoredProcCommand("ForumBans_Insert"))
            {
                DbCommandHelper.AddInt32(DataBase, cmd, "UserID", userID);
                DbCommandHelper.AddString(DataBase, cmd, "Description", description);
                DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                if(expiredOn.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "ExpiredOn", expiredOn.Value);
                }
                DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "BanID");

                res = DataBase.ExecuteNonQuery(cmd) > 0;

                if(res)
                {
                    banID = DbCommandHelper.GeInt32(DataBase, cmd, "@BanID");
                }
            }

            return res;
        }

        public ForumBanData GetForumBan(int banID)
        {
            ForumBanData data = null;

            if(banID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("ForumBans_Select"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "BanID", banID);

                    using(IDataReader reader = DataBase.ExecuteReader(cmd))
                    {
                        if(reader.Read())
                        {
                            data = ReadData(reader);
                        }
                    }
                }
            }

            return data;
        }

        public ForumBanDataCollection GetAllForumBans(int? userID, DateTime? createdOnStart, DateTime? createdOnEnd, DateTime? expiredOnStart, DateTime? expiredOnEnd, int startIndex, int count, out int totalCount)
        {
            ForumBanDataCollection dataCollection = new ForumBanDataCollection();

            using(DbCommand cmd = DataBase.GetStoredProcCommand("ForumBans_SelectAll"))
            {
                if(userID.HasValue)
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "UserID", userID.Value);
                }
                if(createdOnStart.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnStart", createdOnStart.Value);
                }
                if(createdOnEnd.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnEnd", createdOnEnd.Value);
                }
                if(expiredOnStart.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "ExpiredOnStart", expiredOnStart.Value);
                }
                if(expiredOnEnd.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "ExpiredOnEnd", expiredOnEnd.Value);
                }
                DbCommandHelper.AddInt32(DataBase, cmd, "StartIndex", startIndex);
                DbCommandHelper.AddInt32(DataBase, cmd, "Count", count);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "TotalCount");

                using(IDataReader reader = DataBase.ExecuteReader(cmd))
                {
                    while(reader.Read())
                    {
                        dataCollection.Add(ReadData(reader));
                    }
                }

                totalCount = DbCommandHelper.GeInt32(DataBase, cmd, "@TotalCount");
            }

            return dataCollection;
        }

        public bool UpdateForumBan(int banID, int userID, string description, DateTime createdOn, DateTime? expiredOn, DateTime updatedOn)
        {
            bool res = false;

            if(banID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("ForumBans_Update"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "BanID", banID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "UserID", userID);
                    DbCommandHelper.AddString(DataBase, cmd, "Description", description);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                    if(expiredOn.HasValue)
                    {
                        DbCommandHelper.AddDateTime(DataBase, cmd, "ExpiredOn", expiredOn.Value);
                    }
                    DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);

                    res = DataBase.ExecuteNonQuery(cmd) > 0;
                }
            }

            return res;
        }

        public bool DeleteForumBan(int banID)
        {
            bool res = false;

            if(banID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("ForumBans_Delete"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "BanID", banID);

                    res = DataBase.ExecuteNonQuery(cmd) > 0;
                }
            }

            return res;
        }
        #endregion 

        #region Utilities 
        private static ForumBanData ReadData(IDataReader reader)
        {
            ForumBanData data = new ForumBanData();

            data.BanID = DataReaderHelper.ReadInt32(reader, "BanID");
            data.UserID = DataReaderHelper.ReadInt32(reader, "UserID");
            data.Description = DataReaderHelper.ReadString(reader, "Description");
            data.CreatedOn = DataReaderHelper.ReadDateTime(reader, "CreatedOn");
            data.ExpiredOn = DataReaderHelper.ReadNullableDateTime(reader, "ExpiredOn");
            data.UpdatedOn = DataReaderHelper.ReadDateTime(reader, "UpdatedOn");

            return data;
        }
        #endregion
    }
}

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 MIT License


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions