Ejemplo n.º 1
0
        public void EditPost(CreatePost model)
        {
            try
            {
                using (BlogEntities db = new BlogEntities())
                {
                    var oPost = db.post.Find(model.Id);
                    oPost.title        = model.Title;
                    oPost.post_content = model.Content;
                    oPost.image        = model.Image;
                    oPost.id_category  = model.Category.id;

                    db.Entry(oPost).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        public void DeletePost(int id)
        {
            try
            {
                using (BlogEntities db = new BlogEntities())
                {
                    var oPost = db.post.Find(id);

                    if (oPost == null)
                    {
                        throw new Exception();
                    }

                    oPost.is_active = false;

                    db.Entry(oPost).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }