public IHttpActionResult Post(DriverRatingCreate rating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateDriverRatingService(); if (!service.CreateDriverRating(rating)) { return(InternalServerError()); } return(Ok("The driver rating was successfully created.")); }
public bool CreateDriverRating(DriverRatingCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = new DriverRating() { ApplicationUser = _userId, DriverId = model.DriverId, DriverFunScore = model.DriverFunScore, DriverSafetyScore = model.DriverSafetyScore, DriverCleanlinessScore = model.DriverCleanlinessScore, UserCreatedDriverRating = ctx.Users.Single(dr => dr.Id == _userId.ToString()).UserName, }; ctx.DriverRatings.Add(entity); return(ctx.SaveChanges() == 1); } }