// GET: Flight/Create
        public ActionResult Create()
        {
            var model = new FlightModel();
            PopulateDropDownLists(model.AirlineId, model.ArrivalPortId, model.DeparturePortId);

            return View(model);
        }
        // GET: Flight/Delete/5
        public ActionResult Delete(int id)
        {
            var model = new FlightModel();
            try
            {
                var item = flightUnit.FlightRepository.GetByID(id);
                model = ConvertToMvcModel(item);
            }
            catch
            {
                ModelState.AddModelError("",
                    "Unable to delete.");

            }
            return View(model);
        }
        private static DAL.Model.Entities.Flight ConvertToFlight(FlightModel flight)
        {
            return new DAL.Model.Entities.Flight
            {
                FlightNumber = flight.FlightNumber,
                Id = flight.Id,
                AirlineId = flight.AirlineId,
                ArrivalDate = flight.ArrivalDate,
                ArrivalPortId = flight.ArrivalPortId,
                DepartureDate = flight.DepartureDate,
                DeparturePortId = flight.DeparturePortId,
                Gate = flight.Gate,
                Terminal = flight.Terminal,
                Status = (DAL.Model.Enums.FlightStatus)flight.Status,
                PlaceQty = flight.PlaceQty

            };
        }
        FlightModel ConvertToMvcModel(DAL.Model.Entities.Flight item)
        {
            var flight = new FlightModel();
            flight.AirlineId = item.AirlineId;
            flight.ArrivalDate = item.ArrivalDate;
            var airline = new AirlineModel();
            using (var airlineUnit = new AirlineUnit())
            {
                var airlineItem = airlineUnit.AirlineRepository.GetByID(item.AirlineId);
                airline.Id = airlineItem.Id;
                airline.Name = airlineItem.Name;
            }
            flight.Airline = airline;
            flight.ArrivalPortId = item.ArrivalPortId;
            var arrivalPort = new PortModel();
            var departurePort = new PortModel();
            using (var portUnit = new PortUnit())
            {
                var portItem = portUnit.PortRepository.GetByID(item.Id);
                arrivalPort.Id = portItem.Id;
                arrivalPort.Name = portItem.Name;

                portItem = portUnit.PortRepository.GetByID(item.DeparturePortId);
                departurePort.Id = portItem.Id;
                departurePort.Name = portItem.Name;
            }

            flight.ArrivalPort = arrivalPort;
            flight.DepartureDate = item.DepartureDate;
            flight.DeparturePortId = item.DeparturePortId;
            flight.DeparturePort = departurePort;
            flight.FlightNumber = item.FlightNumber;
            flight.Gate = item.Gate;
            flight.Id = item.Id;
            flight.PlaceQty = item.PlaceQty;
            flight.Status = (FlightStatus)item.Status;
            flight.Terminal = item.Terminal;
            return flight;
        }
        // GET: Flight/Edit/5
        public ActionResult Edit(int id)
        {
            var model = new FlightModel();
            try
            {
                var item = flightUnit.FlightRepository.GetByID(id);
                model = ConvertToMvcModel(item);
            }
            catch
            {
                ModelState.AddModelError("",
                    "Unable to edit.");

            }
            PopulateDropDownLists(model.AirlineId, model.ArrivalPortId, model.DeparturePortId);
            return View(model);
        }