Ejemplo n.º 1
0
        /// <summary>
        /// Method to update a post
        /// </summary>
        /// <param name="objPost">Element with all data to save</param>
        /// <param name="strProfile">Profile of user. 1= writer, 2=editor</param>
        /// <param name="strName">User name</param>
        public void Update(Models.Post objPost, string strProfile, string strName)
        {
            using (var context = new Entity.blog_dbEntities())
            {
                //elemento a actualizar
                var update = context.posts.FirstOrDefault(t => t.post_id == objPost.IdPost);

                //Se actualiza
                if (strProfile == "1")
                {
                    //writer profile
                    update.post_title            = objPost.strTitle.Trim();
                    update.post_text             = objPost.strText.Trim();
                    update.post_author           = objPost.strAuthor.Trim();
                    update.post_change           = DateTime.Now;
                    update.post_status_published = objPost.blnStatusToPublish == true ? 1 : 0;
                }
                else
                {
                    //editor profile
                    update.post_status_published = objPost.blnStatusToPublish == true ? 2 : 0;
                    if (objPost.blnStatusToPublish == true)
                    {
                        update.post_approval      = DateTime.Now;
                        update.post_approval_name = strName;
                    }
                }
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Return a list of comments for a post
 /// </summary>
 /// <param name="intIdPost">Id of post</param>
 /// <returns></returns>
 public void Insert(Comments objComment)
 {
     using (var context = new Entity.blog_dbEntities())
     {
         //create model and save to data base
         var model = new Entity.comments();
         model.comment_email     = objComment.strEmail;
         model.comment_text      = objComment.strText;
         model.comment_author    = objComment.strAuthor;
         model.comment_timestamp = DateTime.Now;
         model.comment_post_id   = objComment.intPostId;
         context.comments.Add(model);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Method to insert new posts
 /// </summary>
 /// <param name="objPost">Element with all data to save</param>
 public void Insert(Models.Post objPost)
 {
     using (var context = new Entity.blog_dbEntities())
     {
         //create model and save to data base
         var model = new Entity.posts();
         model.post_title            = objPost.strTitle;
         model.post_text             = objPost.strText;
         model.post_author           = objPost.strAuthor;
         model.post_change           = DateTime.Now;
         model.post_status_published = objPost.blnStatusToPublish == true ? 1 : 0;
         context.posts.Add(model);
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// delete method for posts
        /// </summary>
        /// <param name="strId"></param>
        public void Delete(string strId)
        {
            using (var context = new Entity.blog_dbEntities())
            {
                int idElemento = int.Parse(strId);
                var objPost    = context.posts.FirstOrDefault(p => p.post_id == idElemento);

                if (objPost == null)
                {
                    return;
                }

                context.posts.Remove(objPost);
                context.SaveChanges();
            }
        }