Exemple #1
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> Profile()
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Coś poszło nie tak.";
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                var id      = int.Parse(HttpContext.Session.GetString("Id"));
                var captain = await _captainService.GetAsync(id);

                return(View("CaptainPanel", captain));
            }
            catch (Exception)
            {
                ViewBag.ShowError    = true;
                ViewBag.ErrorMessage = "Coś poszło nie tak.";
                return(RedirectToAction("Index", "Home"));
            }
        }