Exemplo n.º 1
0
        public async Task <IActionResult> AddReservation([FromBody] AddReservation addReservation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            await _reservationService.AddAsync(GetCurrentUserId(), addReservation);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(ReservationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Reservation.ApplicationUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var reservation = await reservationService.AddAsync(model.Reservation);

            return(RedirectToAction(nameof(Confirm), new { reservationId = reservation.ReservationId }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PostAsync(
            [FromBody] SaveReservationResource saveReservationResource)
        {
            var response = await _reservationService.AddAsync(saveReservationResource);

            if (!response.Success)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Post([FromBody] ReservationDto reservationDto)
        {
            try
            {
                await _reservationService.AddAsync(reservationDto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
        public async Task <IActionResult> Reserve(int roomId, [FromBody] ReservationViewModel model)
        {
            model.Reservation.ApplicationUserId = GetUserId();
            model.Reservation.RoomId            = roomId;
            model.Reservation.IsConfirmed       = false;
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }
            var reservation = await reservationService.AddAsync(model.Reservation);

            return(Ok(reservation));
        }
Exemplo n.º 6
0
        public async Task <ApiResponse <Domain.Models.Reservation> > CreateReservation(
            [FromBody] Domain.Models.Reservation reservation)
        {
            if (reservation == null)
            {
                return(new ApiResponse <Domain.Models.Reservation>(ApiResponseCode.BadRequest,
                                                                   reservation)); //return BadRequest();
            }
            try
            {
                await _reservationService.AddAsync(reservation);

                return(new ApiResponse <Domain.Models.Reservation>(ApiResponseCode.OK,
                                                                   reservation)); //return Ok(reservation);
            }
            catch (Exception e)
            {
                return(new ApiResponse <Domain.Models.Reservation>(ApiResponseCode.ServiceUnavailable,
                                                                   null)); //return StatusCode(503, e.Message);
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateReservation(int id, CreateReservation command)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Popraw wymagane błędy";

                return(View("CreateReservation", command));
            }
            try
            {
                var captainId = int.Parse(HttpContext.Session.GetString("Id"));
                var pitch     = await _pitchService.GetAsync(id);

                var captain = await _captainService.GetAsync(captainId);

                await _reservationService.AddAsync(command, captain, pitch);

                ModelState.Clear();
                ViewBag.ShowSuccess    = true;
                ViewBag.SuccessMessage = "Dodawanie rezerwacji zakończone pomyślnie";

                return(View());
            }
            catch (CorruptedOperationException ex)
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = ex.Message;

                return(View());
            }
            catch (Exception)
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Coś poszło nie tak";

                return(View());
            }
        }
        public async Task <IActionResult> Create([FromBody] CreateReservationRequest request)
        {
            await _reservationService.AddAsync(request);

            return(Ok());
        }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> AddAsync(ReservationContract reservation)
        {
            await reservationService.AddAsync(reservation.ToModel());

            return(Created(new Uri(Request.RequestUri, reservation.ReservationId.ToString()), reservation.ReservationId));
        }