Esempio n. 1
0
        public async Task <IActionResult> BookRoom(AddReservationDto addReservationDto)
        {
            if (!ModelState.IsValid)
            {
                foreach (var model in ModelState.Values)
                {
                    foreach (var error in model.Errors)
                    {
                        Console.WriteLine(error.ErrorMessage);
                    }
                }
                return(RedirectToAction("BookRoom", "Reservation", new { roomId = addReservationDto.RoomId }));
            }
            var reservationId = await _reservationService.AddReservationAsync(addReservationDto);

            foreach (var bookedService in addReservationDto.MinuteServices)
            {
                await _reservationService.AssignMinuteServiceAsync(new AddMinuteServiceToReservationDto()
                {
                    ReservationId   = reservationId,
                    MinuteServiceId = bookedService.MinuteServiceId,
                    Duration        = bookedService.Duration
                });
            }

            return(RedirectToAction("Manage", "Reservation", new { reservationId = reservationId }));
        }
Esempio n. 2
0
        public async Task <IActionResult> FormReservation(Reservations model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                ModelState.AddModelError("", "Błąd dodawania rezerwacji.");
                return(View(model));
            }

            var reservation = new Reservations()
            {
                RentFromDate = model.RentFromDate,
                RentToDate   = model.RentToDate,
                MachineId    = id,
                User         = user
            };

            var result = await _reservationService.AddReservationAsync(reservation);

            //TODO:
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        public async Task <IActionResult> AddReservation([FromBody] ReservationDto reservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await reservationService.AddReservationAsync(reservation);

            return(Ok());
        }
Esempio n. 4
0
        public async Task <IActionResult> Add([FromBody] ReservationDto dto)
        {
            try
            {
                var result = await _reservationService.AddReservationAsync(dto).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public async Task <IActionResult> Reserve(int carId, DateTime startDate, DateTime endDate)
        {
            try
            {
                var reservation = await reservationService.AddReservationAsync(User.Identity.Name, carId, startDate, endDate);

                TempData["reservation"] = JsonConvert.SerializeObject(reservation.Adapt <DetailedReservationVM>());

                return(Json(new { redirectToUrl = Url.Action(nameof(ReserveDetails), "RentalPointCar") }));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task<IActionResult> AddReservation(ReservationViewModel newReservation, long roomId, long hotelId)
        {
            if (ModelState.IsValid)
            {
                var errors = await reservationService.ReservationValidationAsync(newReservation, roomId);
                if (errors.Count == 0)
                {
                    var currentUser = await userManager.GetUserAsync(HttpContext.User);
                    var reservationId =
                        await reservationService.AddReservationAsync(newReservation, currentUser.Id, roomId, hotelId);
                    return RedirectToAction(nameof(ConfirmationPage), "Reservation", new { reservationId });
                }

                newReservation.ErrorMessages = errors;
                return View(newReservation);
            }

            return View(newReservation);
        }
        public async Task <IActionResult> OrderFlat(ReservationParamsDTO reservationParams)
        {
            try
            {
                await _reservationService.AddReservationAsync(reservationParams);

                return(Ok());
            }
            catch (EntityNotExistException e)
            {
                return(BadRequest(e.Message));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Esempio n. 8
0
        public async Task Test_AddCustomRule_ShouldThrowException()
        {
            const int maxSeats     = 5;
            var       desiredSeats = CreateSeats().Where(s => s.Id <= (long)maxSeats).Select(Map).ToList();

            PrepareReservationMocks(maxSeats, ScheduleA, ScheduleB, desiredSeats);

            _reservationService.ClearRules();                           // no rules active -> normally it would throw
            _reservationService.AddRule(new SeatAvailableValidation()); // add seat available rule -> should throw now
            Func <Task <ReservationDto> > addReservationAsync = async() => await _reservationService.AddReservationAsync(desiredSeats, ScheduleB.Id, 2L);

            await addReservationAsync.Should().ThrowExactlyAsync <SeatValidationException>();
        }
Esempio n. 9
0
 public async Task <ReservationModel> Post([FromBody] CreateReservationModel reservationModel)
 {
     return(_mapper.Map <ReservationModel>(await _reservationService.AddReservationAsync(reservationModel)));
 }