コード例 #1
0
 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));
        }
コード例 #3
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 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;
     }
 }