Click here to Skip to main content
15,896,154 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 37K   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 TimeZoneDataProvider : DataProviderBase, ITimeZoneDataProvider
    {
        #region Methods
        public bool InsertTimeZone(string name, string displayName, int utcOffset, bool isActive, DateTime createdOn, DateTime updatedOn, out int timeZoneID)
        {
            bool res = false;
            timeZoneID = 0;

            using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_Insert"))
            {
                DbCommandHelper.AddString(DataBase, cmd, "Name", name);
                DbCommandHelper.AddString(DataBase, cmd, "DisplayName", displayName);
                DbCommandHelper.AddInt32(DataBase, cmd, "UtcOffset", utcOffset);
                DbCommandHelper.AddBoolean(DataBase, cmd, "IsActive", isActive);
                DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "TimeZoneID");

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

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

            return res;
        }

        public TimeZoneData GetTimeZone(int timeZoneID)
        {
            TimeZoneData data = null;

            if(timeZoneID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_Select"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TimeZoneID", timeZoneID);

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

            return data;
        }

        public TimeZoneData GetTimeZoneByName(string name)
        {
            TimeZoneData data = null;

            if(!String.IsNullOrEmpty(name))
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_SelectByName"))
                {
                    DbCommandHelper.AddString(DataBase, cmd, "Name", name);

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

            return data;
        }

        public TimeZoneDataCollection GetAllTimeZones(DateTime? createdOnStart, DateTime? createdOnEnd, bool showHidden)
        {
            TimeZoneDataCollection dataCollection = new TimeZoneDataCollection();

            using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_SelectAll"))
            {
                if(createdOnStart.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnStart", createdOnStart.Value);
                }
                if(createdOnEnd.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnEnd", createdOnEnd.Value);
                }
                DbCommandHelper.AddBoolean(DataBase, cmd, "ShowHidden", showHidden);

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

            return dataCollection;
        }

        public bool UpdateTimeZone(int timeZoneID, string name, string displayName, int utcOffset, bool isActive, DateTime createdOn, DateTime updatedOn)
        {
            bool res = false;

            if(timeZoneID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_Update"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TimeZoneID", timeZoneID);
                    DbCommandHelper.AddString(DataBase, cmd, "Name", name);
                    DbCommandHelper.AddString(DataBase, cmd, "DisplayName", displayName);
                    DbCommandHelper.AddInt32(DataBase, cmd, "UtcOffset", utcOffset);
                    DbCommandHelper.AddBoolean(DataBase, cmd, "IsActive", isActive);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);

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

            return res;
        }

        public bool DeleteTimeZone(int timeZoneID)
        {
            bool res = false;

            if(timeZoneID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TimeZones_Delete"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TimeZoneID", timeZoneID);

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

            return res;
        }
        #endregion

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

            data.TimeZoneID = DataReaderHelper.ReadInt32(reader, "TimeZoneID");
            data.Name = DataReaderHelper.ReadString(reader, "Name");
            data.DisplayName = DataReaderHelper.ReadString(reader, "DisplayName");
            data.UtcOffset = DataReaderHelper.ReadInt32(reader, "UtcOffset");
            data.IsActive = DataReaderHelper.ReadBoolean(reader, "IsActive");
            data.CreatedOn = DataReaderHelper.ReadDateTime(reader, "CreatedOn");
            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