Exemplo n.º 1
0
        ///BOTH REPORTS
        public ActionResult GetBothReport()
        {
            ReportVM vm = new ReportVM();

            List <SeatType> Seattypes       = db.SeatType.ToList();
            List <Int32>    chosenseattypes = new List <int>();

            ViewBag.SeatTypes = new MultiSelectList(Seattypes, "SeatTypeID", "Name", chosenseattypes);

            List <City>  AllCities    = db.Cities.ToList();
            List <Int32> chosencities = new List <int>();

            ViewBag.Cities = new MultiSelectList(AllCities, "CityID", "CityName", chosencities);


            List <FlightNumber> allFlightNumbers = db.FlightNumbers.ToList();



            foreach (FlightNumber fn in allFlightNumbers)
            {
                TwoAirport thisroute = new TwoAirport();
                thisroute.City2Airport = fn.endCityAirport;
                thisroute.City1Airport = fn.startCity.Airport;
                thisroute.CityCombo    = thisroute.City1Airport + " to " + thisroute.City2Airport;
                if (db.twoAirporSets.Where(c => c.City1Airport == thisroute.City1Airport && c.City2Airport == thisroute.City2Airport).ToList().Count == 0)
                {
                    db.twoAirporSets.Add(thisroute);
                    db.SaveChanges();
                }
            }

            List <TwoAirport> allroutes      = db.twoAirporSets.ToList();
            List <Int32>      selectedRoutes = new List <int>();

            ViewBag.Routes = new MultiSelectList(allroutes, "TwoAirportID", "CityCombo", selectedRoutes);

            return(View(vm));
        }
Exemplo n.º 2
0
        public ActionResult GetBothReport(ReportVM vm, int[] SeatTypes, int[] Cities, int[] Routes)
        {
            List <Ticket> alltickets = db.Tickets.ToList();

            if (SeatTypes != null)
            {
                int      thisint     = SeatTypes[0];
                SeatType seattypeone = db.SeatType.Where(c => c.SeatTypeID == thisint).ToList().First();
                alltickets = alltickets.Where(c => c.Seat.SeatType.SeatTypeID == seattypeone.SeatTypeID).ToList();
                if (SeatTypes[1] > 0)
                {
                    thisint = SeatTypes[1];
                    List <Ticket> othertickets = db.Tickets.Where(c => c.Seat.SeatType.SeatTypeID == thisint).ToList();
                    foreach (Ticket ticket in othertickets)
                    {
                        alltickets.Add(ticket);
                    }
                }
            }

            if (Cities != null)
            {
                City city1 = db.Cities.Find(Cities[0]);
                alltickets = alltickets.Where(c => c.Flight.FlightNumber.endCityAirport == city1.Airport || c.Flight.FlightNumber.startCity.CityID == Cities[0]).ToList();
                int index = 1;
                while (Cities[index] > 0)
                {
                    int           newint  = Cities[index];
                    City          newCity = db.Cities.Find(Cities[newint]);
                    List <Ticket> moretix = db.Tickets.Where(c => c.Flight.FlightNumber.endCityAirport == newCity.Airport || c.Flight.FlightNumber.startCity.CityID == Cities[index]).ToList();
                    foreach (Ticket ticket in moretix)
                    {
                        alltickets.Add(ticket);
                    }
                    index += 1;
                }
            }

            if (Routes != null)
            {
                TwoAirport route = db.twoAirporSets.Find(Routes[0]);
                alltickets = alltickets.Where(c => c.Flight.FlightNumber.endCityAirport == route.City2Airport || c.Flight.FlightNumber.startCity.Airport == route.City1Airport).ToList();
                int index = 1;
                while (Routes[index] > 0)
                {
                    int           lastint  = Routes[index];
                    TwoAirport    newRoute = db.twoAirporSets.Find(lastint);
                    List <Ticket> moretix  = db.Tickets.Where(c => c.Flight.FlightNumber.endCityAirport == route.City2Airport || c.Flight.FlightNumber.startCity.Airport == route.City1Airport).ToList();
                    foreach (Ticket ticket in moretix)
                    {
                        alltickets.Add(ticket);
                    }
                    index += 1;
                }
            }
            RevenueVM rvm       = new RevenueVM();
            int       seatcount = 0;
            Decimal   Revenue   = 0;

            alltickets = alltickets.Where(c => c.Flight.DepartDateTime >= vm.BegDate && c.Flight.DepartDateTime <= vm.EndDate).ToList();
            List <Flight> newlist = new List <Flight>();

            rvm.Flights = newlist;
            foreach (Ticket ticket in alltickets)
            {
                seatcount += 1;
                rvm.Flights.Add(ticket.Flight);
                if (ticket.Flight.Departed == true)
                {
                    Revenue += ticket.DiscountedFare;
                }
            }
            rvm.SeatCount = seatcount;
            db.RevenueVms.Add(rvm);
            db.SaveChanges();

            return(View("ShowBothReport", rvm));
        }