Beispiel #1
0
        /// <Update>
        /// Update All Fields of Blog_Comments by Id.
        /// </summary>
        /// <param name="blog_Comments">The object of the Blog_Comments class(Domain.Blog_Comments)</param>
        /// <returns>Integer where 0 is failed and 1 is success </returns>
        public int Update(Blog_Comments blog_Comments)
        {
            int update = 0;

            try
            {
                //Creates a database connection and opens up a session
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    //After Session creation, start Transaction.
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        //Proceed action to update data.
                        //Return int (0 or 1)
                        session.Update(blog_Comments.Id, blog_Comments);
                        transaction.Commit();

                        update = 1;
                    } //End using Transaction
                }     //End using session
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }

            return(update);
        }
Beispiel #2
0
        /// <Insert>
        /// Add a Blog_Comment in a Database
        /// </summary>
        /// <param name="blog_Comments">The object of the Blog_Comments class(Domain.Blog_Comments)</param>
        /// <returns>Return Integer</returns>
        public int Insert(Blog_Comments blog_Comments)
        {
            int insert = 0;

            try
            {
                //Creates a database connection and opens up a session
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    //After Session creation, start Transaction.
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        //Proceed action, to save data
                        session.Save(blog_Comments);
                        transaction.Commit();
                        insert = 1;
                    } //End Using trasaction
                }     //End using session
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }
            return(insert);
        }
Beispiel #3
0
        /// <Delete>
        /// Delete a Blog_Comments from Database by Id.
        /// </summary>
        /// <param name="blog_Comments">The object of the Blog_Comments class(Domain.Blog_Comments)</param>
        /// <returns>Integer</returns>
        public int Delete(Blog_Comments blog_Comments)
        {
            int delete = 0;

            try
            {
                //Creates a database connection and opens up a session
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    //After Session creation, start Transaction.
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        //Proceed action, to Delete
                        session.Delete(blog_Comments.Id);
                        transaction.Commit();
                        delete = 1;
                    } //End Trsaction
                }     //End session
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }

            return(delete);
        }
        public ActionResult MakeComment(FormCollection collection)
        {
            try
            {
                int    blogId      = Convert.ToInt32(collection.Get("blogId"));
                string commentText = collection.Get("CommentText");
                string userId      = collection.Get("userId");

                Blog_Comments bComment = new Blog_Comments()
                {
                    BlogId    = blogId,
                    Comment   = commentText,
                    Commenter = userId,
                    InReplyTo = "No-One",
                    TimeStamp = DateTime.Now
                };
                db.Blog_Comments.Add(bComment);
                db.SaveChanges();
                return(RedirectToAction("Article", "Blogs", new { id = blogId }));
            }
            catch
            {
                return(RedirectToAction("Index", "Manage", null));
            }
        }
Beispiel #5
0
        /// <GetAllBlog_Comments>
        /// Get AllBlog Comment.
        /// </summary>
        /// <param name="blog_Comments">The object of the Blog_Comments class(Domain.Blog_Comments)</param>
        /// <returns>Return Blog Comment from Blog_Comments in the form of ICollection Type.</returns>
        public ICollection <Blog_Comments> GetAllBlog_Comments(Blog_Comments blog_Comments)
        {
            ICollection <Blog_Comments> iCol = null;

            try
            {
                //Creates a database connection and opens up a session
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    //Proceed action, to get data.
                    iCol = session.CreateCriteria(typeof(Blog_Comments)).List <Blog_Comments>();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }
            return(iCol);
        }
Beispiel #6
0
 /// <summary>
 /// Map a Comments database Model object to a View Model object for presentation
 /// </summary>
 /// <param name="item">database model object</param>
 /// <returns>view model presentation object</returns>
 public static ViewModel.Blog.Comments ToViewModel(this Blog_Comments item)
 {
     return(Mapper.Map <ViewModel.Blog.Comments>(item));
 }