Click here to Skip to main content
15,886,137 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;
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 TagDataProvider : DataProviderBase, ITagDataProvider
    {
        #region Methods
        public bool InsertTag(string name, DateTime createdOn, DateTime updatedOn, out int tagID)
        {
            bool res = false;
            tagID = 0;

            using(DbCommand cmd = DataBase.GetStoredProcCommand("Tags_Insert"))
            {
                DbCommandHelper.AddString(DataBase, cmd, "Name", name);
                DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);
                DbCommandHelper.AddOutInt32(DataBase, cmd, "TagID");

                res = DataBase.ExecuteNonQuery(cmd) > 0;

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

            return res;
        }

        public bool InsertTagPublicationMapping(int tagID, int publicationID)
        {
            bool res = false;

            if(tagID > 0 && publicationID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TagPublicationMap_Insert"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "PublicationID", publicationID);

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

            return res;
        }

        public TagData GetTag(int tagID)
        {
            TagData data = null;

            if(tagID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Tags_Select"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);

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

            return data;
        }

        public TagData GetTagByName(string name)
        {
            TagData data = null;

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

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

            return data;
        }

        public TagDataCollection GetAllTags(int? publicationID, DateTime? createdOnStart, DateTime? createdOnEnd)
        {
            TagDataCollection dataCollection = new TagDataCollection();

            using(DbCommand cmd = DataBase.GetStoredProcCommand("Tags_SelectAll"))
            {
                if(publicationID.HasValue)
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "PublicationID", publicationID.Value);
                }
                if(createdOnStart.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnStart", createdOnStart.Value);
                }
                if(createdOnEnd.HasValue)
                {
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOnEnd", createdOnEnd.Value);
                }

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

            return dataCollection;
        }

        public bool TagPublicationMappingExists(int tagID, int publicationID)
        {
            bool res = false;

            if(tagID > 0 && publicationID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TagPublicationMap_Contains"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "PublicationID", publicationID);
                    DbCommandHelper.AddOutBoolean(DataBase, cmd, "Result");

                    DataBase.ExecuteNonQuery(cmd);

                    res = DbCommandHelper.GetBoolean(DataBase, cmd, "@Result");
                }
            }

            return res;
        }

        public bool UpdateTag(int tagID, string name, DateTime createdOn, DateTime updatedOn)
        {
            bool res = false;

            if(tagID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Tags_Update"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);
                    DbCommandHelper.AddString(DataBase, cmd, "Name", name);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "CreatedOn", createdOn);
                    DbCommandHelper.AddDateTime(DataBase, cmd, "UpdatedOn", updatedOn);

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

            return true;
        }

        public bool DeleteTag(int tagID)
        {
            bool res = false;

            if(tagID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("Tags_Delete"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);

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

            return res;
        }

        public bool DeleteTagPublicationMapping(int tagID, int publicationID)
        {
            bool res = false;

            if(tagID > 0 && publicationID > 0)
            {
                using(DbCommand cmd = DataBase.GetStoredProcCommand("TagPublicationMap_DeleteAll"))
                {
                    DbCommandHelper.AddInt32(DataBase, cmd, "TagID", tagID);
                    DbCommandHelper.AddInt32(DataBase, cmd, "PublicationID", publicationID);

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

            return res;
        }
        #endregion

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

            data.TagID = DataReaderHelper.ReadInt32(reader, "TagID");
            data.Name = DataReaderHelper.ReadString(reader, "Name");
            data.Count = DataReaderHelper.ReadInt32(reader, "Count");
            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