コード例 #1
0
        public ActionResult Index(Models.Reservation model)
        {
            if (ModelState.IsValid)
            {
                DAL.Models.Reservation reservation = new DAL.Models.Reservation()
                {
                    RentalStartDate = model.RentalStartDate,
                    RentalEndDate   = model.RentalEndDate,
                    Count           = model.Count,
                    TotalCost       = (decimal)Session["TotalCost"], //model.TotalCostString, nie mam pojecia dlaczego nawet w stringu niechce sie to przeslac,
                                                                     //bo w decimallu nie idzie bo ma problem konwertowac z przecinkiem na kropke, robie late
                    UserId      = (int)Session["UserId"],
                    BoardGameId = model.BoardGameId,
                };
                switch (reservationService.AddReservation(reservation))
                {
                case ReservationServiceResponse.SuccessReservation:
                    ModelState.Clear();
                    TempData["SuccessReservation"] = $"Succesfully reserved: {model.BoardGameName}.";
                    return(RedirectToAction("Login", "Login"));

                case ReservationServiceResponse.NotEnoughBoardGame:
                    ViewBag.NotEnoughBoardGameMessage = "We do not have enough board games.";
                    return(RedirectToAction("Details", "BoardGameDetailsOffer", new { boardGameId = model.BoardGameId }));

                default:
                    break;
                }
            }
            return(View(model));
        }
        public ActionResult Index(Models.Reservation model)
        {
            if (ModelState.IsValid)
            {
                DAL.Models.Reservation reservation = new DAL.Models.Reservation()
                {
                    RentalStartDate = model.RentalStartDate,
                    RentalEndDate   = model.RentalEndDate,
                    Count           = model.Count,
                    TotalCost       = (decimal)Session["TotalCost"], //model.TotalCostString, nie mam pojecia dlaczego nawet w stringu niechce sie to przeslac,
                                                                     //bo w decimallu nie idzie bo ma problem konwertowac z przecinkiem na kropke, robie late
                    UserId      = (int)Session["UserId"],
                    BoardGameId = model.BoardGameId,
                };
                switch (reservationService.AddReservation(reservation))
                {
                case ReservationServiceResponse.SuccessReservation:
                    //string imagePath = model.ImagePath;
                    ModelState.Clear();
                    //ViewBag.ImagePath = imagePath;
                    TempData["SuccessReservation"] = $"Z powodzeniem dokonano rezerwacji: {model.BoardGameName}.";
                    return(RedirectToAction("Login", "Login"));

                case ReservationServiceResponse.NotEnoughBoardGame:
                    ViewBag.NotEnoughBoardGameMessage = "Nie posiadamy wystarczającej liczby gier.";
                    return(RedirectToAction("Details", "BoardGameDetailsOffer", new { boardGameId = model.BoardGameId }));

                default:
                    break;
                }
            }
            return(View(model));
        }