public void Delete(int id)
 {
     try
     {
         var post = context.Posts.Find(id);
         if (post == null)
         {
             return;
         }
         var postLikes = context.Likes.Where(l => l.PostId == id);
         foreach (var like in postLikes)
         {
             like.IsLiked = false;
             context.Entry(like).State = EntityState.Modified;
         }
         var postComments = context.Comments.Where(c => c.PostId == id);
         foreach (var comment in postComments)
         {
             comment.IsDeleted            = true;
             context.Entry(comment).State = EntityState.Modified;
         }
         post.IsDeleted            = true;
         context.Entry(post).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#2
0
        public IHttpActionResult PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.comment_id)
            {
                return(BadRequest());
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutGroup_Posts(int id, Group_Posts group_Posts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != group_Posts.post_id)
            {
                return(BadRequest());
            }

            db.Entry(group_Posts).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Group_PostsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public IHttpActionResult PutBlocked_Users(int id, Blocked_Users blocked_Users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != blocked_Users.user_id)
            {
                return(BadRequest());
            }

            db.Entry(blocked_Users).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Blocked_UsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutUser([FromUri] int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.user_id)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(user));
        }
 public void Update(string id, User user)
 {
     try
     {
         context.Entry(user).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Update(int id, Comment t)
 {
     try
     {
         context.Entry(t).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#8
0
 public void Update(string id, FriendRequest t)
 {
     try
     {
         context.Entry(t).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }