public RentalRequestDto Find(int id) { RentalRequest rentalRequest = _repository.Find(id); RentalRequestDto rentalRequestDto = _mapper.Map <RentalRequestDto>(rentalRequest); return(rentalRequestDto); }
public RentalRegistration RentVehicle(RentalRequestDto rentalRequestDto) { Vehicle vehicle; switch (rentalRequestDto.VehicleCategory) { case VehicleCategoryEnum.SmallCar: vehicle = new SmallCar(rentalRequestDto.DashboardMileage); break; case VehicleCategoryEnum.Van: vehicle = new Van(rentalRequestDto.DashboardMileage); break; case VehicleCategoryEnum.MiniBus: vehicle = new MiniBus(rentalRequestDto.DashboardMileage); break; default: throw new ArgumentOutOfRangeException(); } var customer = new Customer(rentalRequestDto.CustomerBirthday); var booking = new Booking(rentalRequestDto.StartOfRental); return(_rentalRegistration.RentVehicle(vehicle, customer, booking)); }
public RentalRequestDto Update(RentalRequestDto rentalRequestDto) { RentalRequest rentalRequest = _mapper.Map <RentalRequest>(rentalRequestDto); _repository.Update(rentalRequest); _dal.Save(); return(_mapper.Map <RentalRequestDto>(rentalRequest)); }
public RentalRequestDto Remove(RentalRequestDto rentalRequest) { var temp = _repository.Remove(rentalRequest.Id); _dal.Save(); RentalRequestDto rentalRequestDto = _mapper.Map <RentalRequestDto>(temp); return(rentalRequestDto); }
public RentalRequestBuilder Begin() { _rentalRequestDto = new RentalRequestDto { VehicleCategory = VehicleCategoryEnum.Van, CustomerBirthday = DateTime.UtcNow.AddYears(-23), DashboardMileage = 10000, StartOfRental = DateTime.UtcNow.AddDays(10) }; return(this); }
public RentalRequestDto Create(RentalRequestDto rentalRequestDto) { RentalRequest rentalRequest = _mapper.Map <RentalRequest>(rentalRequestDto); User user = _userManager.FindById(rentalRequestDto.UserId); rentalRequest.User = user; _repository.Create(rentalRequest); _dal.Save(); return(_mapper.Map <RentalRequestDto>(rentalRequest)); }
public IHttpActionResult GetRentalRequest(int id) { RentalRequestDto rentalRequest = _rentalRequestService.Find(id); if (rentalRequest == null) { return(NotFound()); } RentalRequestViewModel view = _mapper.Map <RentalRequestViewModel>(rentalRequest); return(Ok(view)); }
public IHttpActionResult DeleteRentalRequest(int id) { String userName = AuthManager.User.Identity.Name; String userId = _userService.GetUserId(userName); RentalRequestDto request = _rentalRequestService.Find(id); if (request.UserId != userId) { return(NotFound()); } RentalRequestDto deletedRequest = _rentalRequestService.Remove(request); return(Ok(_mapper.Map <RentalRequestViewModel>(deletedRequest))); }
// you can return RentalRequestViewModel and same thing is other controllers public IHttpActionResult Create(RentalRequestCreateViewModel rentalRequestCreateModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } String userName = AuthManager.User.Identity.Name; String userId = _userService.GetUserId(userName); RentalRequestDto rentalRequest = _mapper.Map <RentalRequestDto>(rentalRequestCreateModel); rentalRequest.UserId = userId; RentalRequestDto createdRentalRequest = _rentalRequestService.Create(rentalRequest); return(Ok(_mapper.Map <RentalRequestViewModel>(createdRentalRequest))); }
public Rental CreateRental(RentalRequestDto rentalRequestDto) { if (!ModelState.IsValid) { throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.BadRequest); } Rental rental = null; var customer = _context.Customers.Single(c => c.Id == rentalRequestDto.CustomerId); foreach (var movieId in rentalRequestDto.MoviesId) { var movie = _context.Movies.SingleOrDefault(c => c.Id == movieId); if (movie.NumberAvailable == 0) { throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.BadRequest); } movie.NumberAvailable--; rental = new Rental { Customer = customer, Movies = movie, DateRented = DateTime.Now }; _context.Rentals.Add(rental); _context.SaveChanges(); rentalRequestDto.Id = rental.Id; } return(rental); }