public IHttpActionResult Put([FromUri] int specialId, [FromBody] SpecialEdit special) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateSpecialService(); if (!service.UpdateSpecial(specialId, special)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateSpecial(int specialId, SpecialEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Specials .Single(e => e.SpecialId == specialId); entity.SpecialId = model.SpecialId; entity.ProductId = model.ProductId; entity.DayOfWeek = model.DayOfWeek; entity.ProductSpecialPrice = model.ProductSpecialPrice; return(ctx.SaveChanges() == 1); } }