Click here to Skip to main content
15,895,656 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;
using System.Data;
using System.Data.Common;
using SiberTek.Xenta.Data.Entities;
using SiberTek.Xenta.Data.Entities.Collections;
using SiberTek.Xenta.Data.Utils;
using SiberTek.Xenta.Enums;

namespace SiberTek.Xenta.Data.Providers
{
    public class PollDataProvider : DataProviderBase, IPollDataProvider
    {
        #region Methods
        public bool InsertPoll(int languageID, string title, DateTime startDate, DateTime endDate, bool isActive, DateTime createdOn, DateTime updatedOn, out int pollID)
        {
            bool res = false;
            pollID = 0;

            using(DbCommand cmd = DataBase.GetStoredProcCommand("Polls_Insert"))
            {
                DbCommandHelper.AddInt32(DataBase, cmd, "LanguageID", languageID);
                DbCommandHelper.AddString(DataBase, cmd, "Title", title);
                DbCommandHelper.AddDateTime(DataBase, cmd, "StartDate", startDate);
                DbCommandHelper.AddDateTime(DataBase, cmd, "EndDate", endDate);
                DbCommandHelper.AddBoolean(DataBase, cmd, "IsActive", isActive);
                DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "PollID");

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

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

            return res;
        }

        public PollData GetPoll(int pollID)
        {
            PollData data = null;

            if(pollID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Polls_Select"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "PollID", pollID);

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

            return data;
        }

        public PollDataCollection GetAllPolls(int? languageID, DateTime? startDate, DateTime? endDate, DateTime? createdOnStart, DateTime? createdOnEnd, bool showHidden)
        {
            PollDataCollection dataCollection = new PollDataCollection();

            using(DbCommand cmd = DataBase.GetStoredProcCommand("Polls_SelectAll"))
            {
                if(languageID.HasValue)
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "LanguageID", languageID.Value);
                }
                if(startDate.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "StartDate", startDate.Value);
                }
                if(endDate.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "EndDate", endDate.Value);
                }
                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 UpdatePoll(int pollID, int languageID, string title, DateTime startDate, DateTime endDate, bool isActive, DateTime createdOn, DateTime updatedOn)
        {
            bool res = false;

            if(pollID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Polls_Update"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "PollID", pollID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "LanguageID", languageID);
                    DbCommandHelper.AddString(DataBase, cmd, "Title", title);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "StartDate", startDate);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "EndDate", endDate);
                    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 DeletePoll(int pollID)
        {
            bool res = false;

            if(pollID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Polls_Delete"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "PollID", pollID);

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

            return res;
        }
        #endregion

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

            data.PollID = DataReaderHelper.ReadInt32(reader, "PollID");
            data.LanguageID = DataReaderHelper.ReadInt32(reader, "LanguageID");
            data.Title = DataReaderHelper.ReadString(reader, "Title");
            data.StartDate = DataReaderHelper.ReadDateTime(reader, "StartDate");
            data.EndDate = DataReaderHelper.ReadDateTime(reader, "EndDate");
            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