Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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());
        }