예제 #1
0
        // READ
        public IActionResult Index()
        {
            if (User.IsInRole("Admin") == false)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var planeModels = _planes.GetAll();

            var listingResult = planeModels
                                .Select(result => new PlaneListingModel
            {
                Id           = result.Id,
                MaxCapacity  = _planes.GetMaxCapacity(result.Id),
                Type         = (_planes.GetType(result.Id) == 1) ? "Passenger plane" : "Cargo plane",
                Manufacturer = _planes.GetManufacturer(result.Id),
                Model        = _planes.GetModel(result.Id),
                // Take only the year and cast to string
                Year        = _planes.GetYear(result.Id).Year.ToString(),
                FlyingHours = _planes.GetFlyingHours(result.Id),
                Identifier  = _planes.GetIdentifier(result.Id),
                Status      = _planes.GetStatus(result.Id)
            });

            var model = new PlaneIndexModel()
            {
                Planes = listingResult
            };

            return(View(model));
        }
예제 #2
0
        public void Land(int Id)
        {
            Flight LandingFlight = GetById(Id);

            LandingFlight.Status       = 2;
            LandingFlight.Plane.Status = 0;

            // Fetch flight employees
            IEnumerable <FlightEmployee> FlightEmployeeObjects     = _context.FlightEmployees.Where(flightemployee => flightemployee.FlightId == LandingFlight.Id);
            List <FlightEmployee>        FlightEmployeeObjectsList = FlightEmployeeObjects.ToList();

            // Edit employees' status and add hours
            for (int i = 0; i < FlightEmployeeObjectsList.Count(); i++)
            {
                _employees.ChangeStatus(FlightEmployeeObjectsList[i].EmployeeId);
                _employees.AddHours(FlightEmployeeObjectsList[i].EmployeeId, LandingFlight.Duration / Config.Scale);
            }

            // Add hours to plane
            Plane LandingPlane = LandingFlight.Plane;

            _planes.AddHours(LandingPlane.Id, LandingFlight.Duration / 3600);

            // Check if the plane needs assitance
            if (_planes.GetFlyingHours(LandingPlane.Id) >= 200)
            {
                IEnumerable <Maintenance> Maintenances     = _context.Maintenances.Where(maintenance => maintenance.PlaneId == LandingPlane.Id);
                List <Maintenance>        MaintenancesList = Maintenances.ToList();

                if ((Maintenances == null) || (_planes.GetFlyingHours(LandingPlane.Id) > (200 * MaintenancesList.Count())))
                {
                    MaintainPlane(LandingPlane.Id);
                }
            }
            _context.SaveChanges();
        }