public IActionResult Search(string search, int page = 1) { List <Museums> list = new List <Museums>(); if (search != null) { list = museumRepository.Search(search); } else { list = museumRepository.GetMuseums(); } List <MuseumVM> model = new List <MuseumVM>(); const int PageSize = 12; var count = list.Count(); if (page == 1) { list = list.Skip(0).Take(PageSize).ToList(); } else { list = list.Skip((page - 1) * PageSize).Take(PageSize).ToList(); } if (count <= PageSize) { ViewBag.MaxPage = 1; } else { if (count % PageSize == 0) { ViewBag.MaxPage = (count / PageSize); } else { ViewBag.MaxPage = (count / PageSize) + 1; } } ViewBag.Page = page; ViewBag.NextPage = page + 1; foreach (Museums x in list) { MuseumVM vm = new MuseumVM(); vm.Id = x.Id; vm.Address = x.Address; vm.Name = x.Name; vm.Image = imageRepository.GetMuseumImage(x.Id); if (vm.Image != null) { vm.ImageId = vm.Image.Id; } model.Add(vm); } return(View("Index", model)); }
public IActionResult Index() { InfoVM model = new InfoVM(); model.MuseumsRegistrated = museumRepository.MuseumsRegistrated(); model.MuseumsRegMonth = museumRepository.MuseumsRegMonth(); model.TicketsRevenue = 0; model.TicketsRevenueMonth = 0; model.TicketsSale = 0; model.TicketsSaleMonth = 0; model.UsersRegistrated = clientRepository.GetRegClients(); model.UsersRegMonth = clientRepository.GetRegClientsMonth(); model.ActiveMuseums = 0; model.InactiveMuseums = 0; model.museumTicketSales = new List <MuseumTicketSale>(); IEnumerable <Museums> museums = museumRepository.GetMuseums(); museums = museums.Where(x => x.OnlineTickets).ToList(); foreach (Museums x in museums) { int total = ticketRepository.GetSum(x.UserId); model.museumTicketSales.Add(new MuseumTicketSale { Museum = x.Name, Quantity = total }); if (x.User.Active) { model.ActiveMuseums++; } else { model.InactiveMuseums++; } model.TicketsSale += total; model.TicketsSaleMonth += ticketRepository.GetMonthSum(x.UserId); model.TicketsRevenue += ticketRepository.GetTotal(x.UserId); model.TicketsRevenueMonth += ticketRepository.GetMonthTotal(x.UserId); } model.TotalMuseumTicketSales = model.museumTicketSales.Select(x => x.Quantity).Sum(); return(View(model)); }
public IActionResult Index() { IEnumerable <Museums> model = museumRepository.GetMuseums(); return(View(model)); }