public ActionResult Save(AgreementViewModel agreementVieModel) { var rentViewModel = agreementVieModel.rentViewModel; if (!ModelState.IsValid) { return(RedirectToAction("RentCar", new { CarDtoId = agreementVieModel.CarId, firstDayRent = rentViewModel.firstDayRent, lastDayRent = rentViewModel.lastDayRent, PickUpLocationId = rentViewModel.PickUpLocationId, ReturnLocationId = rentViewModel.ReturnLocationId })); } var agreementDto = Mapper.Map <AgreementDto>(agreementVieModel); if (agreementDto.WithDriver) { agreementDto.TotalPrice += 50 * agreementDto.NumberOfDays; } switch (agreementDto.InsuranceType) { case InsuranceType.Standard: { double percent = agreementDto.TotalPrice * 0.05; percent = percent - percent % 1; try { agreementDto.TotalPrice = checked (agreementDto.TotalPrice + (int)percent); } catch (OverflowException ex) { // logging agreementDto.TotalPrice = int.MaxValue; } break; } case InsuranceType.Lux: { double percent = agreementDto.TotalPrice * 0.10; percent = percent - percent % 1; try { agreementDto.TotalPrice = checked (agreementDto.TotalPrice + (int)percent); } catch (OverflowException ex) { // logging agreementDto.TotalPrice = int.MaxValue; } break; } } agreementDto.IsPayed = true; var id = rentService.AddAgreement(agreementDto); var pickUpCarDelivery = new CarDeliveryDto() { AgreementId = id, DateOfDelivery = rentViewModel.firstDayRent, IsDeliveryToUser = true, NoDamage = true, PlaceId = rentViewModel.PickUpLocationId, CarId = agreementVieModel.CarId }; rentService.AddCarDelivery(pickUpCarDelivery); var returnCarDelivery = new CarDeliveryDto() { AgreementId = id, DateOfDelivery = rentViewModel.lastDayRent, IsDeliveryToUser = false, NoDamage = false, PlaceId = rentViewModel.ReturnLocationId, CarId = agreementVieModel.CarId }; rentService.AddCarDelivery(returnCarDelivery); return(RedirectToAction("Result")); }