Example #1
0
        public RentalRequestDto Find(int id)
        {
            RentalRequest    rentalRequest    = _repository.Find(id);
            RentalRequestDto rentalRequestDto = _mapper.Map <RentalRequestDto>(rentalRequest);

            return(rentalRequestDto);
        }
Example #2
0
        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));
        }
Example #3
0
        public RentalRequestDto Update(RentalRequestDto rentalRequestDto)
        {
            RentalRequest rentalRequest = _mapper.Map <RentalRequest>(rentalRequestDto);

            _repository.Update(rentalRequest);
            _dal.Save();

            return(_mapper.Map <RentalRequestDto>(rentalRequest));
        }
Example #4
0
        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);
        }
Example #6
0
        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));
        }
Example #7
0
        public IHttpActionResult GetRentalRequest(int id)
        {
            RentalRequestDto rentalRequest = _rentalRequestService.Find(id);

            if (rentalRequest == null)
            {
                return(NotFound());
            }

            RentalRequestViewModel view = _mapper.Map <RentalRequestViewModel>(rentalRequest);

            return(Ok(view));
        }
Example #8
0
        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)));
        }
Example #9
0
        // 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)));
        }
Example #10
0
        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);
        }