Пример #1
0
 public void AddPost(Posts post)
 {
     try
     {
         db.Posts.Add(post);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.InnerException.Message);
     }
 }
Пример #2
0
        public void UpdatePost(Posts post)
        {
            try
            {
                Posts orgin = db.Posts.Where(p => p.PostsID == post.PostsID).Single();
                orgin.Header = post.Header;
                orgin.Content = post.Content;
                orgin.LastEdited = post.LastEdited;
                orgin.EditedBy = post.EditedBy;
                orgin.Edited = true;

                db.Entry(post).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw new Exception(e.InnerException.Message);
            }
        }