public IActionResult GetAllTickets() { var flights = _flightService.GetAll(); var tickets = new List <TicketViewModel>(); foreach (var item in flights) { var itemTickets = _ticketService.GetAll().Where(x => x.FlightID == item.Id).ToList(); foreach (var ticket in itemTickets) { var viewTicket = new TicketViewModel() { Id = ticket.Id, Price = ticket.Price, FlightArrivingDate = item.FlightArrivingDate, FlightDepartmentDate = item.FlightDepartmentDate, LocationFrom = item.LocationFrom, LocationTo = item.LocationTo }; tickets.Add(viewTicket); } } if (tickets.Count != 0) { return(View(tickets)); } return(View()); }
public void CreateTest() { //Arrange var flight = new Flight() { LocationFrom = "Lviv", LocationTo = "Kyiv" }; var flightDTO = new FlightDTO() { LocationFrom = "Lviv", LocationTo = "Kyiv" }; List <Flight> flights = new List <Flight>(); flightMockRepository.Setup(x => x.GetAll()).Returns(flights); flightMockRepository.Setup(x => x.Create(flight)).Callback((Flight f) => { flights.Add(new Flight()); }); mapper.Setup(x => x.Map <Flight>(flightDTO)).Returns(flight); flightService.Create(flightDTO); Assert.Single(flightService.GetAll()); }
public IActionResult Search(FlightViewModel flightViewModel) { var flights = _flightService.GetAll().Where(t => t.LocationFrom == flightViewModel.cityFrom). Where(t => t.LocationTo == flightViewModel.cityTo). Where(t => t.FlightDepartmentDate.Year == flightViewModel.dateTime.Year). Where(t => t.FlightDepartmentDate.Month == flightViewModel.dateTime.Month). Where(t => t.FlightDepartmentDate.Day == flightViewModel.dateTime.Day); //flights = flights.OrderBy(t => t.Tickets.Max(k=>k.Price)).ToList(); var tickets = new List <TicketViewModel>(); foreach (var iteam in flights) { var likes = _unitOfWork.LikeRepository.GetAll().Where(t => t.FlightId == iteam.Id); var listTicket = _unitOfWork.TicketRepository.GetQuery().Include(t => t.Basket).Where(t => t.Basket == null).Where(t => t.FlightId == iteam.Id); foreach (var ticket in listTicket) { if (ticket.FlightId == iteam.Id) { var viewTicket = new TicketViewModel() { Id = ticket.Id, Price = ticket.Price, FlightArrivingDate = iteam.FlightArrivingDate, FlightDepartmentDate = iteam.FlightDepartmentDate, LocationFrom = iteam.LocationFrom, LocationTo = iteam.LocationTo, CollLike = likes.Count() }; tickets.Add(viewTicket); } } } if (tickets.Count != 0) { //tickets = tickets.OrderBy(t => t.Price).ThenBy(t => t.FlightArrivingDate).ToList(); //return View(new ListObj { ticketViews = tickets } ); return(View(tickets)); } return(View()); }