Ejemplo n.º 1
0
        public async Task <IActionResult> CreateReservation([FromBody] List <AddReservationDto> reservations)
        {
            try
            {
                var reservationInfos = _mapper.Map <List <Reservation> >(reservations);
                await _manager.CreateReservation(reservationInfos);

                return(CreatedAtAction(nameof(GetReservations), new { includeRemove = true }, reservationInfos));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(Ok(new JsonMessageResult(e.Message, 0, 0)));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Create(ReservationCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                string userID = User.FindFirstValue(ClaimTypes.NameIdentifier);
                Table  table  = _tableManager.GetFreeTable(vm.BusinessID, vm.AmountOfGuests, vm.ReservationDate.Value);
                if (table != null)
                {
                    Reservation newReservation = new Reservation
                    {
                        UserID              = userID,
                        TableID             = table.ID,
                        AmountOfGuests      = vm.AmountOfGuests,
                        ReservationDateFrom = vm.ReservationDate,
                        ReservationDateTo   = vm.ReservationDate.Value.AddHours(1)
                    };
                    _reservationManager.CreateReservation(newReservation);
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    vm.FoundTable = false;
                }
            }

            // Can't pass objects with vm -> opnieuw opvragen
            Business business = _businessManager.GetBusinessForDetails(vm.BusinessID);

            if (business == null)
            {
                return(NotFound());
            }
            vm.BusinessToReserve = business;
            vm.BusinessHours     = _businessManager.GetBusinessHours(vm.BusinessID).Data;
            return(View(vm));
        }
        public async Task <ActionResult> CreateReservation([FromBody] ReservationRequest request)
        {
            var result = await _reservationManager.CreateReservation(request);

            return(Ok(result));
        }