public IHttpActionResult Put(DriverRatingUpdate rating) { if (!ModelState.IsValid) { return(BadRequest()); } var service = CreateDriverRatingService(); if (!service.UpdateDriverRating(rating)) { return(InternalServerError()); } return(Ok("The driver rating has been successfully updated.")); }
public bool UpdateDriverRating(DriverRatingUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .DriverRatings .Single(e => e.DriverRatingId == model.DriverRatingId && e.ApplicationUser == _userId); entity.DriverId = model.DriverId; entity.DriverFunScore = model.DriverFunScore; entity.DriverSafetyScore = model.DriverSafetyScore; entity.DriverCleanlinessScore = model.DriverCleanlinessScore; return(ctx.SaveChanges() == 1); } }