public IHttpActionResult PutComment(int id, Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != 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 PutRecipe(string id, Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.Id) { return(BadRequest()); } db.Entry(recipe).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual void Update(T entity) { entity.ModifiedOnUtc = DateTime.UtcNow; Context.Set <T>().Attach(entity); Context.Entry(entity).State = System.Data.Entity.EntityState.Modified; Context.SaveChanges(); }