public ActionResult Rate(TripRateInputModel model) { if (!this.ModelState.IsValid) { return this.View(model); } string userId = this.User.Identity.GetUserId(); Trip trip = this.TripServices.GetById(model.TripId); bool userCanRate = this.TripProvider.UserCanRateTrip(trip, userId); if (!userCanRate) { return this.RedirectToRoute("/"); } TripNotification tripNotification = this.TripNotificationServices.GetTripFinishTripNotificationByTripAndForUser(model.TripId, userId); if (trip.DriverId == userId) { var passengers = trip.Passengers .Where(p => p.IsDeleted == false && p.Approved == true) .Select(p => p.UserId) .ToList(); for (int i = 0; i < passengers.Count; i++) { string passengerUsername = passengers.ElementAt(i); int passengerRating = this.TripProvider.GetValidRate(model.PassengerRatings.ElementAt(i)); this.RatingServices.RateUser(passengerUsername, userId, passengerRating, tripNotification); } this.TempData[WebApplicationConstants.TempDataMessageKey] = "You have succesfully rate your passengers."; } else { int driverRating = this.TripProvider.GetValidRate(model.DriverRating); this.RatingServices.RateUser(trip.DriverId, userId, driverRating, tripNotification); this.TempData[WebApplicationConstants.TempDataMessageKey] = "You have succesfully rate this driver."; } return this.RedirectToRoute("TripDetails", new { id = model.TripId, slug = string.Format("{0}-{1}", trip.From.Name, trip.To.Name) }); }
public ActionResult Rate(int id) { string userId = this.User.Identity.GetUserId(); Trip trip = this.TripServices.GetById(id); bool userCanRate = this.TripProvider.UserCanRateTrip(trip, userId); if (!userCanRate) { return this.RedirectToRoute("/"); } var viewModel = new TripRateInputModel() { TripId = id, CurrentUserIsDriver = trip.DriverId == userId }; var passengers = trip.Passengers .Where(p => p.IsDeleted == false && p.Approved == true) .Select(p => p.User); var mapperdPassnegers = passengers.AsQueryable().To<BaseUserViewModel>().ToList(); viewModel.Passengers = mapperdPassnegers; viewModel.Driver = this.Mapper.Map<BaseUserViewModel>(trip.Driver); viewModel.TripFromName = trip.From.Name; viewModel.TripToName = trip.To.Name; viewModel.DateOfLeavingFormatted = trip.DateOfLeaving.ToString("dd MMM yyyy HH:mm"); return this.View(viewModel); }