public void AddPost(Posts post) { try { db.Posts.Add(post); db.SaveChanges(); } catch (Exception e) { throw new Exception(e.InnerException.Message); } }
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); } }