public ActionResult OrdersPageForDate(int dateId) { var userName = User.Identity.Name.ToLower(); var loginId = loginService.GetLoginByName(userName)?.Id ?? 0; var date = dateService.GetDate(dateId); var play = playService.GetPlay(date.PlayId); var datesOfPlay = dateService.GetDatesOfPlay(play.Id).ToList(); var dates = datesOfPlay.Select(q => new DateViewModel { Id = q.Id, Date = q.PlayDate }).ToList(); var orders = new OrdersForDateViewModel { DateId = dateId, LoginId = loginId, Categories = new List <CategoriesForTableViewModel>(), Dates = dates, PlayName = play.Name, AuthorName = play.Author.Name }; var categories = categoriesService.GetCategories(); orders.Categories = categories.Select(category => { var ticketsPaidCount = ordersService.GetPaidOrders(category.Id, dateId); var orderedTicketsCount = ordersService.GetNonPaidOrders(category.Id, dateId); return(new CategoriesForTableViewModel { Category = category.Name, AvailableTickets = category.TotalTickets - ticketsPaidCount - orderedTicketsCount, TicketPrice = category.TicketPrice, TotalTickets = category.TotalTickets, OrderedTickets = orderedTicketsCount, PaidTickets = ticketsPaidCount, CategoryId = category.Id, Quantity = 0 }); }).ToList(); return(View(orders)); }