public async Task <IActionResult> CreateComment(int id, PitchViewModel command) { if (string.IsNullOrWhiteSpace(command.NewComment.Content)) { TempData["CommentFlag"] = true; TempData["CommentMessage"] = "Comment can't be empty!"; return(RedirectToAction("Pitch", "Pitch", id)); } try { var accountId = int.Parse(HttpContext.Session.GetString("Id")); var account = await _accountService.GetAsync(accountId); var pitch = await _pitchService.GetAsync(id); await _commentService.CreateCommentAsync(command.NewComment, account, pitch); return(RedirectToAction("Pitch", "Pitch", id)); } catch (InternalSystemException ex) { TempData["CommentFlag"] = true; TempData["CommentMessage"] = ex.Message; return(RedirectToAction("Pitch", "Pitch", id)); } catch (Exception) { TempData["CommentFlag"] = true; TempData["CommentMessage"] = "Something went wrong!"; return(RedirectToAction("Pitch", "Pitch", id)); } }
public async Task <IActionResult> Pitch(string id) { try { var pitchId = int.Parse(id); var pitch = await _pitchservice.GetAsync(pitchId); var pitchViewModel = new Infrastructure.ViewModels.Pitch.PitchViewModel(pitch); return(View(pitchViewModel)); } catch (Exception) { return(RedirectToAction("Index", "Home")); } }
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()); } }