Click here to Skip to main content
15,880,364 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.8K   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 PollAnswerDataProvider : DataProviderBase, IPollAnswerDataProvider
    {
        #region Methods
        public bool InsertPollAnswer(int pollID, string title, int count, int displayOrder, DateTime createdOn, DateTime updatedOn, out int answerID)
        {
            bool res = false;
            answerID = 0;

            using(DbCommand cmd = DataBase.GetStoredProcCommand("PollAnswers_Insert"))
            {
                DbCommandHelper.AddInt32(DataBase, cmd, "PollID", pollID);
                DbCommandHelper.AddString(DataBase, cmd, "Title", title);
                DbCommandHelper.AddInt32(DataBase, cmd, "Count", count);
                DbCommandHelper.AddInt32(DataBase, cmd, "DisplayOrder", displayOrder);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "AnswerID");
                DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);

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

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

            return res;
        }

        public PollAnswerData GetPollAnswer(int answerID)
        {
            PollAnswerData data = null;

            if(answerID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("PollAnswers_Select"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "AnswerID", answerID);

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

            return data;
        }

        public PollAnswerDataCollection GetPollAnswersByPollID(int pollID)
        {
            PollAnswerDataCollection dataCollection = new PollAnswerDataCollection();

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

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

            return dataCollection;
        }

        public bool UpdatePollAnswer(int answerID, int pollID, string title, int count, int displayOrder, DateTime createdOn, DateTime updatedOn)
        {
            bool res = false;

            if(answerID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("PollAnswers_Update"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "AnswerID", answerID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "PollID", pollID);
                    DbCommandHelper.AddString(DataBase, cmd, "Title", title);
                    DbCommandHelper.AddInt32(DataBase, cmd, "Count", count);
                    DbCommandHelper.AddInt32(DataBase, cmd, "DisplayOrder", displayOrder);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);

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

            return res;
        }

        public bool DeletePollAnswer(int answerID)
        {
            bool res = false;

            if(answerID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("PollAnswers_Delete"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "AnswerID", answerID);

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

            return res;
        }
        #endregion

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

            data.AnswerID = DataReaderHelper.ReadInt32(reader, "AnswerID");
            data.PollID = DataReaderHelper.ReadInt32(reader, "PollID");
            data.Title = DataReaderHelper.ReadString(reader, "Title");
            data.Count = DataReaderHelper.ReadInt32(reader, "Count");
            data.DisplayOrder = DataReaderHelper.ReadInt32(reader, "DisplayOrder");
            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