public static bool UpdatePost(this DBEntities DB, PostView postView) { Post postToUpdate = DB.Posts.Find(postView.Id); postView.CopyToPost(postToUpdate); DB.Entry(postToUpdate).State = EntityState.Modified; DB.SaveChanges(); PostsLastUpdate = DateTime.Now; return(true); }
public static List <PostView> ToPostViewList(this DBEntities DB, IEnumerable <Post> posts) { List <PostView> postViews = new List <PostView>(); foreach (var post in posts) { PostView postview = post.ToPostView(); postview.CurrentUserLike = DB.AlreadyLike(post.Id, OnlineUsers.CurrentUser.Id); postViews.Add(postview); } return(postViews); }
public static PostView AddPost(this DBEntities DB, PostView postView) { Post post = postView.ToPost(); BeginTransaction(DB); post = DB.Posts.Add(post); DB.SaveChanges(); if (post.ParentPostId != 0) { PostsChild pc = new PostsChild { PostId = post.ParentPostId, ChildPostId = post.Id }; DB.PostsChilds.Add(pc); DB.SaveChanges(); } Commit(); PostsLastUpdate = DateTime.Now; return(post.ToPostView()); }