public bool UpdatePost(EditAPost model) { using (var ctx = new ApplicationDbContext()) { var postToUpdate = ctx .Posts .Single(e => e.PostId == model.PostId && e.UserId == _userId); postToUpdate.PostTitle = model.PostTitle; postToUpdate.PostText = model.PostText; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(EditAPost postToEdit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreatePostService(); if (!service.UpdatePost(postToEdit)) { return(InternalServerError()); } return(Ok()); }