public IHttpActionResult Post(RenterRatingCreate rating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateRenterRatingService(); if (!service.CreateRenterRating(rating)) { return(InternalServerError()); } return(Ok("The renter rating was succesffully created.")); }
public bool CreateRenterRating(RenterRatingCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = new RenterRating() { ApplicationUser = _userId, RenterId = model.RenterId, RenterCleanlinessScore = model.RenterCleanlinessScore, RenterSafetyScore = model.RenterSafetyScore, RenterPunctualityScore = model.RenterPunctualityScore, UserCreatedRenterRating = ctx.Users.Single(rr => rr.Id == _userId.ToString()).UserName, }; ctx.RenterRatings.Add(entity); return(ctx.SaveChanges() == 1); } }