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

YaBlogEngineMVC - A Tiny Blog Engine written in ASP.NET MVC

Rate me:
Please Sign up or sign in to vote.
4.48/5 (8 votes)
9 Apr 2013CPOL7 min read 51.9K   2.3K   27  
This article presents a very small scale blog engine developed using ASP.NET MVC, Entity Framework and SQLServer.
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata

[assembly: EdmRelationshipAttribute("yaBlogDbModel", "FK_Comments_Blogs", "Blogs", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(YaBlogEngineMVC.Models.Blog), "Comments", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(YaBlogEngineMVC.Models.Comment), true)]
[assembly: EdmRelationshipAttribute("yaBlogDbModel", "FK_Blogs_Categories", "Category", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(YaBlogEngineMVC.Models.Category), "Blog", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(YaBlogEngineMVC.Models.Blog), true)]

#endregion

namespace YaBlogEngineMVC.Models
{
    #region Contexts
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class yaBlogDbEntities : ObjectContext
    {
        #region Constructors
    
        /// <summary>
        /// Initializes a new yaBlogDbEntities object using the connection string found in the 'yaBlogDbEntities' section of the application configuration file.
        /// </summary>
        public yaBlogDbEntities() : base("name=yaBlogDbEntities", "yaBlogDbEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new yaBlogDbEntities object.
        /// </summary>
        public yaBlogDbEntities(string connectionString) : base(connectionString, "yaBlogDbEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new yaBlogDbEntities object.
        /// </summary>
        public yaBlogDbEntities(EntityConnection connection) : base(connection, "yaBlogDbEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        #endregion
    
        #region Partial Methods
    
        partial void OnContextCreated();
    
        #endregion
    
        #region ObjectSet Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Blog> Blogs
        {
            get
            {
                if ((_Blogs == null))
                {
                    _Blogs = base.CreateObjectSet<Blog>("Blogs");
                }
                return _Blogs;
            }
        }
        private ObjectSet<Blog> _Blogs;
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Comment> Comments
        {
            get
            {
                if ((_Comments == null))
                {
                    _Comments = base.CreateObjectSet<Comment>("Comments");
                }
                return _Comments;
            }
        }
        private ObjectSet<Comment> _Comments;
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Category> Categories
        {
            get
            {
                if ((_Categories == null))
                {
                    _Categories = base.CreateObjectSet<Category>("Categories");
                }
                return _Categories;
            }
        }
        private ObjectSet<Category> _Categories;

        #endregion

        #region AddTo Methods
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Blogs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToBlogs(Blog blog)
        {
            base.AddObject("Blogs", blog);
        }
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Comments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToComments(Comment comment)
        {
            base.AddObject("Comments", comment);
        }
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToCategories(Category category)
        {
            base.AddObject("Categories", category);
        }

        #endregion

    }

    #endregion

    #region Entities
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="yaBlogDbModel", Name="Blog")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Blog : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Blog object.
        /// </summary>
        /// <param name="id">Initial value of the ID property.</param>
        /// <param name="categoryId">Initial value of the CategoryId property.</param>
        /// <param name="subject">Initial value of the Subject property.</param>
        /// <param name="body">Initial value of the Body property.</param>
        /// <param name="datePosted">Initial value of the DatePosted property.</param>
        /// <param name="postedBy">Initial value of the PostedBy property.</param>
        public static Blog CreateBlog(global::System.Int32 id, global::System.Int32 categoryId, global::System.String subject, global::System.String body, global::System.DateTime datePosted, global::System.String postedBy)
        {
            Blog blog = new Blog();
            blog.ID = id;
            blog.CategoryId = categoryId;
            blog.Subject = subject;
            blog.Body = body;
            blog.DatePosted = datePosted;
            blog.PostedBy = postedBy;
            return blog;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    OnIDChanging(value);
                    ReportPropertyChanging("ID");
                    _ID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ID");
                    OnIDChanged();
                }
            }
        }
        private global::System.Int32 _ID;
        partial void OnIDChanging(global::System.Int32 value);
        partial void OnIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 CategoryId
        {
            get
            {
                return _CategoryId;
            }
            set
            {
                OnCategoryIdChanging(value);
                ReportPropertyChanging("CategoryId");
                _CategoryId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("CategoryId");
                OnCategoryIdChanged();
            }
        }
        private global::System.Int32 _CategoryId;
        partial void OnCategoryIdChanging(global::System.Int32 value);
        partial void OnCategoryIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Subject
        {
            get
            {
                return _Subject;
            }
            set
            {
                OnSubjectChanging(value);
                ReportPropertyChanging("Subject");
                _Subject = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Subject");
                OnSubjectChanged();
            }
        }
        private global::System.String _Subject;
        partial void OnSubjectChanging(global::System.String value);
        partial void OnSubjectChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Body
        {
            get
            {
                return _Body;
            }
            set
            {
                OnBodyChanging(value);
                ReportPropertyChanging("Body");
                _Body = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Body");
                OnBodyChanged();
            }
        }
        private global::System.String _Body;
        partial void OnBodyChanging(global::System.String value);
        partial void OnBodyChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.DateTime DatePosted
        {
            get
            {
                return _DatePosted;
            }
            set
            {
                OnDatePostedChanging(value);
                ReportPropertyChanging("DatePosted");
                _DatePosted = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("DatePosted");
                OnDatePostedChanged();
            }
        }
        private global::System.DateTime _DatePosted;
        partial void OnDatePostedChanging(global::System.DateTime value);
        partial void OnDatePostedChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String PostedBy
        {
            get
            {
                return _PostedBy;
            }
            set
            {
                OnPostedByChanging(value);
                ReportPropertyChanging("PostedBy");
                _PostedBy = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("PostedBy");
                OnPostedByChanged();
            }
        }
        private global::System.String _PostedBy;
        partial void OnPostedByChanging(global::System.String value);
        partial void OnPostedByChanged();

        #endregion

    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("yaBlogDbModel", "FK_Comments_Blogs", "Comments")]
        public EntityCollection<Comment> Comments
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Comment>("yaBlogDbModel.FK_Comments_Blogs", "Comments");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Comment>("yaBlogDbModel.FK_Comments_Blogs", "Comments", value);
                }
            }
        }
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("yaBlogDbModel", "FK_Blogs_Categories", "Category")]
        public Category Category
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("yaBlogDbModel.FK_Blogs_Categories", "Category").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("yaBlogDbModel.FK_Blogs_Categories", "Category").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Category> CategoryReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("yaBlogDbModel.FK_Blogs_Categories", "Category");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Category>("yaBlogDbModel.FK_Blogs_Categories", "Category", value);
                }
            }
        }

        #endregion

    }
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="yaBlogDbModel", Name="Category")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Category : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Category object.
        /// </summary>
        /// <param name="id">Initial value of the ID property.</param>
        /// <param name="categoryName">Initial value of the CategoryName property.</param>
        /// <param name="createdBy">Initial value of the CreatedBy property.</param>
        public static Category CreateCategory(global::System.Int32 id, global::System.String categoryName, global::System.String createdBy)
        {
            Category category = new Category();
            category.ID = id;
            category.CategoryName = categoryName;
            category.CreatedBy = createdBy;
            return category;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    OnIDChanging(value);
                    ReportPropertyChanging("ID");
                    _ID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ID");
                    OnIDChanged();
                }
            }
        }
        private global::System.Int32 _ID;
        partial void OnIDChanging(global::System.Int32 value);
        partial void OnIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String CategoryName
        {
            get
            {
                return _CategoryName;
            }
            set
            {
                OnCategoryNameChanging(value);
                ReportPropertyChanging("CategoryName");
                _CategoryName = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("CategoryName");
                OnCategoryNameChanged();
            }
        }
        private global::System.String _CategoryName;
        partial void OnCategoryNameChanging(global::System.String value);
        partial void OnCategoryNameChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String CreatedBy
        {
            get
            {
                return _CreatedBy;
            }
            set
            {
                OnCreatedByChanging(value);
                ReportPropertyChanging("CreatedBy");
                _CreatedBy = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("CreatedBy");
                OnCreatedByChanged();
            }
        }
        private global::System.String _CreatedBy;
        partial void OnCreatedByChanging(global::System.String value);
        partial void OnCreatedByChanged();

        #endregion

    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("yaBlogDbModel", "FK_Blogs_Categories", "Blog")]
        public EntityCollection<Blog> Blogs
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Blog>("yaBlogDbModel.FK_Blogs_Categories", "Blog");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Blog>("yaBlogDbModel.FK_Blogs_Categories", "Blog", value);
                }
            }
        }

        #endregion

    }
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="yaBlogDbModel", Name="Comment")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Comment : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Comment object.
        /// </summary>
        /// <param name="id">Initial value of the ID property.</param>
        /// <param name="blogId">Initial value of the BlogId property.</param>
        /// <param name="name">Initial value of the Name property.</param>
        /// <param name="comment1">Initial value of the Comment1 property.</param>
        /// <param name="datePosted">Initial value of the DatePosted property.</param>
        public static Comment CreateComment(global::System.Int32 id, global::System.Int32 blogId, global::System.String name, global::System.String comment1, global::System.DateTime datePosted)
        {
            Comment comment = new Comment();
            comment.ID = id;
            comment.BlogId = blogId;
            comment.Name = name;
            comment.Comment1 = comment1;
            comment.DatePosted = datePosted;
            return comment;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ID
        {
            get
            {
                return _ID;
            }
            set
            {
                if (_ID != value)
                {
                    OnIDChanging(value);
                    ReportPropertyChanging("ID");
                    _ID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ID");
                    OnIDChanged();
                }
            }
        }
        private global::System.Int32 _ID;
        partial void OnIDChanging(global::System.Int32 value);
        partial void OnIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 BlogId
        {
            get
            {
                return _BlogId;
            }
            set
            {
                OnBlogIdChanging(value);
                ReportPropertyChanging("BlogId");
                _BlogId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("BlogId");
                OnBlogIdChanged();
            }
        }
        private global::System.Int32 _BlogId;
        partial void OnBlogIdChanging(global::System.Int32 value);
        partial void OnBlogIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                OnNameChanging(value);
                ReportPropertyChanging("Name");
                _Name = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Name");
                OnNameChanged();
            }
        }
        private global::System.String _Name;
        partial void OnNameChanging(global::System.String value);
        partial void OnNameChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Comment1
        {
            get
            {
                return _Comment1;
            }
            set
            {
                OnComment1Changing(value);
                ReportPropertyChanging("Comment1");
                _Comment1 = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Comment1");
                OnComment1Changed();
            }
        }
        private global::System.String _Comment1;
        partial void OnComment1Changing(global::System.String value);
        partial void OnComment1Changed();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.DateTime DatePosted
        {
            get
            {
                return _DatePosted;
            }
            set
            {
                OnDatePostedChanging(value);
                ReportPropertyChanging("DatePosted");
                _DatePosted = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("DatePosted");
                OnDatePostedChanged();
            }
        }
        private global::System.DateTime _DatePosted;
        partial void OnDatePostedChanging(global::System.DateTime value);
        partial void OnDatePostedChanged();

        #endregion

    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("yaBlogDbModel", "FK_Comments_Blogs", "Blogs")]
        public Blog Blog
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Blog>("yaBlogDbModel.FK_Comments_Blogs", "Blogs").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Blog>("yaBlogDbModel.FK_Comments_Blogs", "Blogs").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Blog> BlogReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Blog>("yaBlogDbModel.FK_Comments_Blogs", "Blogs");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Blog>("yaBlogDbModel.FK_Comments_Blogs", "Blogs", value);
                }
            }
        }

        #endregion

    }

    #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 Code Project Open License (CPOL)


Written By
Architect
India India

I Started my Programming career with C++. Later got a chance to develop Windows Form applications using C#. Currently using C#, ASP.NET & ASP.NET MVC to create Information Systems, e-commerce/e-governance Portals and Data driven websites.

My interests involves Programming, Website development and Learning/Teaching subjects related to Computer Science/Information Systems. IMO, C# is the best programming language and I love working with C# and other Microsoft Technologies.

  • Microsoft Certified Technology Specialist (MCTS): Web Applications Development with Microsoft .NET Framework 4
  • Microsoft Certified Technology Specialist (MCTS): Accessing Data with Microsoft .NET Framework 4
  • Microsoft Certified Technology Specialist (MCTS): Windows Communication Foundation Development with Microsoft .NET Framework 4

If you like my articles, please visit my website for more: www.rahulrajatsingh.com[^]

  • Microsoft MVP 2015

Comments and Discussions