示例#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);
            }
        }
示例#2
0
        public void CreatePost(CreatePost model)
        {
            try
            {
                using (BlogEntities db = new BlogEntities())
                {
                    var oPost = new post();
                    oPost.title         = model.Title;
                    oPost.post_content  = model.Content;
                    oPost.image         = model.Image;
                    oPost.id_category   = model.Category.id;
                    oPost.creation_date = model.CreationDate;
                    oPost.is_active     = true;

                    db.post.Add(oPost);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
示例#3
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);
            }
        }