/// <summary> /// Gets all need information in ViewBag /// </summary> /// <param name="id">Date id</param> private void getViewBagForOrderPage(int id) { ViewBag.DateId = id; DatePlay currentDate = datesDb.GetDateById(id); Play play = playsDb.GetPlayById(currentDate.PlayId); ViewBag.Play = play; ViewBag.Genre = genresDb.GetGenreById(play.GenreId); ViewBag.Author = authorsDb.GetAuthorById(play.AuthorId); ViewBag.Dates = datesDb.GetDatesByIdPlay(play.Id).OrderBy(x => x.Date).ToList(); ViewBag.TotalCountBalconySeats = TheaterInformation.TotalCountBalconySeats; ViewBag.PriceBalconySeats = TheaterInformation.PriceBalcony; ViewBag.FreeBalconySeats = (TheaterInformation.TotalCountBalconySeats - ordersDb.GetCountBusySeetsByDateIdAndCategory(id, 0)); ViewBag.TotalCountParterreSeats = TheaterInformation.TotalCountParterreSeats; ViewBag.PriceParterreSeats = TheaterInformation.PriceParterre; ViewBag.FreeParterreSeats = (TheaterInformation.TotalCountParterreSeats - ordersDb.GetCountBusySeetsByDateIdAndCategory(id, 1)); }
/// <summary> /// Gets all need information in ViewBag /// </summary> /// <param name="id">Date id</param> private void getViewBagForOrderPage(int id) { ViewBag.DateId = id; IOrderDao orders = OrdersTableConnection.Instance; IDateDao datesDb = DatesTableConnection.Instance; DatePlay currentDate = datesDb.GetDateById(id); IPlayDao playsDb = PlaysTableConnection.Instance; Play play = playsDb.GetPlayById(currentDate.PlayId); ViewBag.Play = play; IGenreDao genresDb = GenresTableConnection.Instance; ViewBag.Genre = genresDb.GetGenreById(play.GenreId); IAuthorDao authorsDb = AuthorsTableConnection.Instance; ViewBag.Author = authorsDb.GetAuthorById(play.AuthorId); ViewBag.Dates = datesDb.GetDatesByIdPlay(play.Id).OrderBy(x => x.Date).ToList(); ViewBag.TotalCountBalconySeats = TheaterInformation.TotalCountBalconySeats; ViewBag.PriceBalconySeats = TheaterInformation.PriceBalcony; ViewBag.FreeBalconySeats = (TheaterInformation.TotalCountBalconySeats - orders.GetCountBusySeetsByDateIdAndCategory(id, 0)); ViewBag.TotalCountParterreSeats = TheaterInformation.TotalCountParterreSeats; ViewBag.PriceParterreSeats = TheaterInformation.PriceParterre; ViewBag.FreeParterreSeats = (TheaterInformation.TotalCountParterreSeats - orders.GetCountBusySeetsByDateIdAndCategory(id, 1)); }
public ActionResult DatePlayUpdate(DatePlay date, string dateCheck, string playName) { try { DateTime newDate; if (DateTime.TryParse(dateCheck, out newDate) && (datesDb.GetAllDates().Where(datePlay => datePlay.Date == newDate).Count() == 0 || datesDb.GetAllDates().First(datePlay => datePlay.Date == newDate).Id == date.Id)) { date.PlayId = playsDb.GetPlaysByName(playName).First().Id; date.Date = newDate; datesDb.Update(date); messagesDatePlayTable = Resources.Resource.MessageUpdated; return(RedirectToAction("DatePlaysTable", "Admin")); } else { messagesDatePlayTable = Resources.Resource.Error; return(RedirectToAction("DatePlaysTable", "Admin")); } } catch (Exception e) { messagesDatePlayTable = Resources.Resource.Error; return(RedirectToAction("DatePlaysTable", "Admin")); } }
public void Create(DatePlay date) { using (SqlConnection connection = new SqlConnection(ConnectionStr)) { connection.Open(); SqlCommand command = new SqlCommand(createDate, connection); command.Parameters.AddWithValue("@playId", date.PlayId); command.Parameters.AddWithValue("@date", date.Date); command.ExecuteNonQuery(); } }
public ActionResult Order(Order order, int dateId) { IDateDao dates = DatesTableConnection.Instance; IOrderDao orders = OrdersTableConnection.Instance; DatePlay date = dates.GetDateById(dateId); Play play = PlaysTableConnection.Instance.GetPlayById(date.PlayId); getViewBagForOrderPage(dateId); if (date.Date < DateTime.Now) { ModelState.AddModelError("Error order time!", Resources.Resource.ErrorOrderTime); return(View()); } if (!isTrueOrder(order, orders, dateId)) { ModelState.AddModelError("Error order!", Resources.Resource.ErrorOrderNumber); return(View()); } else { try { orders.AddOrder(new Order(0, dateId, CurrentUserService.GetCurrentUser().Id, (int)order.Category, order.Quantity, TheaterInformation.GetPriceByCategoryId((int)order.Category) * order.Quantity, 0)); return(View("OrderAccepted")); } catch (InvalidOperationException) { ModelState.AddModelError("Error order!", Resources.Resource.ErrorOrder); return(View()); } } }