public int Update(PlaneAirportModel planeAirportModel)
        {
            this.PlaneAirportRepository.Update(planeAirportModel.GetModel());
            var result = this.UnitOfWork.SaveChanges();

            return(result);
        }
        public PlaneAirportModel CreateViewModel(PlaneAirport model)
        {
            PlaneAirportModel viewModel = null;

            if (model != null)
            {
                viewModel = new PlaneAirportModel();
                CommonMethods.CopyObjectProperties(model, viewModel);
            }

            return(viewModel);
        }
        //Plane 1 -> 7 : Flight in Viet Nam
        //Plane 8 -> 14 : Flight from Viet Nam to other region
        //Plane 15 -> 20: Flight in other region
        public ActionResult GeneratePlaneAirport()
        {
            var planeList      = this.PlaneService.FindAll().ToList();
            var airportList    = this.AirportService.FindAll().ToList();
            var airportVietNam = airportList.Where(airport => airport.Country.Name.Equals(Constant.CONST_DB_NAME_VIETNAM)).ToList();
            var airportRegion  = airportList.Where(airport => !airport.Country.Name.Equals(Constant.CONST_DB_NAME_VIETNAM)).ToList();
            var planeIndex     = 1;

            foreach (var plane in planeList)
            {
                var result = new List <AirportModel>();

                if (planeIndex >= 1 && planeIndex <= 7)
                {
                    result = RandomAirport(airportVietNam, 10);
                }
                else if (planeIndex >= 8 && planeIndex <= 14)
                {
                    var result1 = RandomAirport(airportVietNam, 10);
                    result = result1.Concat(RandomAirport(airportRegion, 10)).OrderByDescending(airport => airport.Name).ToList();
                }
                else
                {
                    result = RandomAirport(airportRegion, 20);
                }

                foreach (var aiport in result)
                {
                    var planeAirport = new PlaneAirportModel {
                        AirportID = aiport.ID,
                        PlaneID   = plane.ID
                    };

                    this.PlaneAirportService.Insert(planeAirport);
                }
                ++planeIndex;
            }

            return(View("Done"));
        }
Exemplo n.º 4
0
        public ActionResult AddNewPlane(FormCollection collection)
        {
            var plane = new PlaneModel
            {
                Airline   = collection.Get("airline"),
                SeatMapID = int.Parse(collection.Get("planetype")),
                Status    = Constant.CONST_PLANE_STATUS_READY
            };
            var planeID    = this.PlaneService.Insert(plane);
            var firstclass = int.Parse(collection.Get("firstclass"));
            var business   = int.Parse(collection.Get("business"));
            var economy    = int.Parse(collection.Get("economy"));
            var order      = 1;

            //for FirstClass
            if (firstclass > 0)
            {
                var planeSeatClass = new PlaneSeatClassModel
                {
                    PlaneID     = planeID,
                    SeatClassID = Constant.CONST_DB_SEAT_CLASS_FIRSTCLASS_ID,
                    Capacity    = firstclass,
                    Price       = double.Parse(collection.Get("firstclassprice")),
                    Order       = order++
                };

                this.PlaneSeatClassService.Insert(planeSeatClass);
            }

            //for Business
            if (business > 0)
            {
                var planeSeatClass = new PlaneSeatClassModel
                {
                    PlaneID     = planeID,
                    SeatClassID = Constant.CONST_DB_SEAT_CLASS_BUSINESS_ID,
                    Capacity    = business,
                    Price       = double.Parse(collection.Get("businessprice")),
                    Order       = order++
                };

                this.PlaneSeatClassService.Insert(planeSeatClass);
            }

            //for Economy
            if (economy > 0)
            {
                var planeSeatClass = new PlaneSeatClassModel
                {
                    PlaneID     = planeID,
                    SeatClassID = Constant.CONST_DB_SEAT_CLASS_ECONOMY_ID,
                    Capacity    = economy,
                    Price       = double.Parse(collection.Get("economyprice")),
                    Order       = order++
                };

                this.PlaneSeatClassService.Insert(planeSeatClass);
            }

            var air = collection.Get("airport").Split(',');

            foreach (var a in air)
            {
                var planeAirport = new PlaneAirportModel
                {
                    PlaneID   = planeID,
                    AirportID = int.Parse(a)
                };

                this.PlaneAirportService.Insert(planeAirport);
            }
            TempData["msg"] = "success-Plane add successfully";

            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public ActionResult UpdatePlane(FormCollection collection)
        {
            var currentPlane = this.PlaneService.Find(int.Parse(collection.Get("planeid")));

            if (currentPlane != null && !currentPlane.Status.Equals(Constant.CONST_PLANE_STATUS_ONLINE))
            {
                if (CheckPlaneTicketBooked(currentPlane.Flights.Select(flight => flight.ID).ToList()))
                {
                    var airport       = collection.Get("airport").Split(',').ToList();
                    var airportDB     = currentPlane.PlaneAirports.Select(idairport => idairport.AirportID.ToString()).ToList();
                    var airportDelete = airportDB.Where(airportid => airport.IndexOf(airportid) == -1).ToList();
                    var airportAdd    = airport.Where(airportid => airportDB.IndexOf(airportid) == -1).ToList();

                    foreach (var id in airportDelete)
                    {
                        var currentAirport = this.PlaneAirportService.Find(currentPlane.ID, int.Parse(id));

                        if (currentAirport.Plane.Flights.Count == 0)
                        {
                            this.PlaneAirportService.Delete(currentAirport.PlaneID, currentAirport.AirportID);
                        }
                        else
                        {
                            TempData["msg"] = "success-Plane changed status successfully";

                            return(RedirectToAction("Index"));
                        }
                    }

                    foreach (var air in airportAdd)
                    {
                        var planeAirport = new PlaneAirportModel
                        {
                            PlaneID   = currentPlane.ID,
                            AirportID = int.Parse(air)
                        };

                        this.PlaneAirportService.Insert(planeAirport);
                    }

                    currentPlane.Airline   = collection.Get("airline");
                    currentPlane.SeatMapID = int.Parse(collection.Get("planetype"));
                    this.PlaneService.Update(currentPlane);

                    var firstclass = this.PlaneSeatClassService.Find(currentPlane.ID, Constant.CONST_DB_SEAT_CLASS_FIRSTCLASS_ID);
                    var business   = this.PlaneSeatClassService.Find(currentPlane.ID, Constant.CONST_DB_SEAT_CLASS_BUSINESS_ID);
                    var economy    = this.PlaneSeatClassService.Find(currentPlane.ID, Constant.CONST_DB_SEAT_CLASS_ECONOMY_ID);

                    UpdatePlaneSeatClass(firstclass, currentPlane.ID, int.Parse(collection.Get("firstclass")), double.Parse(collection.Get("firstclassprice")), Constant.CONST_DB_SEAT_CLASS_FIRSTCLASS_ID);
                    UpdatePlaneSeatClass(business, currentPlane.ID, int.Parse(collection.Get("business")), double.Parse(collection.Get("businessprice")), Constant.CONST_DB_SEAT_CLASS_BUSINESS_ID);
                    UpdatePlaneSeatClass(economy, currentPlane.ID, int.Parse(collection.Get("economy")), double.Parse(collection.Get("economyprice")), Constant.CONST_DB_SEAT_CLASS_ECONOMY_ID);
                }
                else
                {
                    TempData["msg"] = "error-Update plane failed because plane has ticket booked";
                }
            }
            else
            {
                TempData["msg"] = "error-Update plane failed because plane is online";
            }

            return(RedirectToAction("Index"));
        }