// GET: /Edit
        public ActionResult Edit(int id)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Access"] = "WriteAccess";
            }

            PseudoCityOrOfficeMaintenance pseudoCityOrOfficeMaintenance = pseudoCityOrOfficeMaintenanceRepository.GetPseudoCityOrOfficeMaintenance(id);

            //Check Exists
            if (pseudoCityOrOfficeMaintenance == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            PseudoCityOrOfficeMaintenanceVM pseudoCityOrOfficeMaintenanceVM = new PseudoCityOrOfficeMaintenanceVM();

            //Checkboxes
            pseudoCityOrOfficeMaintenance.ActiveFlagNonNullable = pseudoCityOrOfficeMaintenance.ActiveFlag.Value;
            pseudoCityOrOfficeMaintenance.SharedPseudoCityOrOfficeFlagNonNullable          = pseudoCityOrOfficeMaintenance.SharedPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.CWTOwnedPseudoCityOrOfficeFlagNonNullable        = pseudoCityOrOfficeMaintenance.CWTOwnedPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.ClientDedicatedPseudoCityOrOfficeFlagNonNullable = pseudoCityOrOfficeMaintenance.ClientDedicatedPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.ClientGDSAccessFlagNonNullable = pseudoCityOrOfficeMaintenance.ClientGDSAccessFlag.Value;
            pseudoCityOrOfficeMaintenance.DevelopmentOrInternalPseudoCityOrOfficeFlagNonNullable = pseudoCityOrOfficeMaintenance.DevelopmentOrInternalPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.CubaPseudoCityOrOfficeFlagNonNullable       = pseudoCityOrOfficeMaintenance.CubaPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.GovernmentPseudoCityOrOfficeFlagNonNullable = pseudoCityOrOfficeMaintenance.GovernmentPseudoCityOrOfficeFlag.Value;
            pseudoCityOrOfficeMaintenance.GDSThirdPartyVendorFlagNonNullable          = pseudoCityOrOfficeMaintenance.GDSThirdPartyVendorFlag.Value;

            pseudoCityOrOfficeMaintenanceRepository.EditForDisplay(pseudoCityOrOfficeMaintenance);

            pseudoCityOrOfficeMaintenanceVM.PseudoCityOrOfficeMaintenance = pseudoCityOrOfficeMaintenance;

            //IATAs
            IATARepository iataRepository = new IATARepository();

            pseudoCityOrOfficeMaintenanceVM.IATAs = new SelectList(iataRepository.GetAllIATAs().ToList(), "IATAId", "IATANumber", pseudoCityOrOfficeMaintenance.IATAId);

            //GDSs
            GDSRepository GDSRepository = new GDSRepository();

            pseudoCityOrOfficeMaintenanceVM.GDSs = new SelectList(GDSRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName", pseudoCityOrOfficeMaintenance.GDSCode);

            //PseudoCityOrOfficeAddresses
            //Addresses will only display based upon the role of the system user and their Location.
            PseudoCityOrOfficeAddressRepository pseudoCityOrOfficeAddressRepository = new PseudoCityOrOfficeAddressRepository();

            pseudoCityOrOfficeMaintenanceVM.PseudoCityOrOfficeAddresses = new SelectList(pseudoCityOrOfficeAddressRepository.GetUserPseudoCityOrOfficeAddresses().ToList(), "PseudoCityOrOfficeAddressId", "FirstAddressLine", pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeAddressId);

            //PseudoCityOrOfficeDefinedRegions
            PseudoCityOrOfficeDefinedRegionRepository pseudoCityOrOfficeDefinedRegionRepository = new PseudoCityOrOfficeDefinedRegionRepository();

            pseudoCityOrOfficeMaintenanceVM.PseudoCityOrOfficeDefinedRegions = new SelectList(
                pseudoCityOrOfficeDefinedRegionRepository.GetPseudoCityOrOfficeDefinedRegionsForGlobalRegionCode(pseudoCityOrOfficeMaintenance.GlobalRegionCode).ToList(),
                "PseudoCityOrOfficeDefinedRegionId",
                "PseudoCityOrOfficeDefinedRegionName",
                pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeDefinedRegionId
                );

            //ExternalNames
            ExternalNameRepository externalNameRepository = new ExternalNameRepository();

            pseudoCityOrOfficeMaintenanceVM.ExternalNames = new SelectList(externalNameRepository.GetAllExternalNames().ToList(), "ExternalNameId", "ExternalName1", pseudoCityOrOfficeMaintenance.ExternalNameId);

            //PseudoCityOrOfficeTypes
            PseudoCityOrOfficeTypeRepository pseudoCityOrOfficeTypeRepository = new PseudoCityOrOfficeTypeRepository();

            pseudoCityOrOfficeMaintenanceVM.PseudoCityOrOfficeTypes = new SelectList(pseudoCityOrOfficeTypeRepository.GetAllPseudoCityOrOfficeTypes().ToList(), "PseudoCityOrOfficeTypeId", "PseudoCityOrOfficeTypeName", pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeTypeId);

            //PseudoCityOrOfficeLocationTypes
            PseudoCityOrOfficeLocationTypeRepository pseudoCityOrOfficeLocationTypeRepository = new PseudoCityOrOfficeLocationTypeRepository();

            pseudoCityOrOfficeMaintenanceVM.PseudoCityOrOfficeLocationTypes = new SelectList(pseudoCityOrOfficeLocationTypeRepository.GetAllPseudoCityOrOfficeLocationTypes().ToList(), "PseudoCityOrOfficeLocationTypeId", "PseudoCityOrOfficeLocationTypeName", pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeLocationTypeId);

            //FareRedistributions
            FareRedistributionRepository fareRedistributionRepository = new FareRedistributionRepository();

            pseudoCityOrOfficeMaintenanceVM.FareRedistributions = new SelectList(
                fareRedistributionRepository.GetFareRedistributionsByGDSCode(pseudoCityOrOfficeMaintenance.GDSCode).ToList(),
                "FareRedistributionId",
                "FareRedistributionName",
                pseudoCityOrOfficeMaintenance.FareRedistributionId
                );

            //GDSThirdPartyVendors
            GDSThirdPartyVendorRepository gdsThirdPartyVendorRepository = new GDSThirdPartyVendorRepository();

            pseudoCityOrOfficeMaintenanceVM.GDSThirdPartyVendors = gdsThirdPartyVendorRepository.GetAllGDSThirdPartyVendors();

            List <SelectListItem> gdsThirdPartyVendors = new List <SelectListItem>();

            foreach (GDSThirdPartyVendor gdsThirdPartyVendor in pseudoCityOrOfficeMaintenanceVM.GDSThirdPartyVendors)
            {
                gdsThirdPartyVendors.Add(
                    new SelectListItem
                {
                    Value = gdsThirdPartyVendor.GDSThirdPartyVendorId.ToString(),
                    Text  = gdsThirdPartyVendor.GDSThirdPartyVendorName
                }
                    );
            }

            List <GDSThirdPartyVendor> selectedGDSThirdPartyVendors = gdsThirdPartyVendorRepository.GetGDSThirdPartyVendorsByPseudoCityOrOfficeMaintenanceId(pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeMaintenanceId);

            pseudoCityOrOfficeMaintenanceVM.GDSThirdPartyVendorsList = new MultiSelectList(
                gdsThirdPartyVendors,
                "Value",
                "Text",
                selectedGDSThirdPartyVendors.Select(x => x.GDSThirdPartyVendorId).ToArray()
                );

            //ClientSubUnits
            pseudoCityOrOfficeMaintenanceVM.ClientSubUnits = pseudoCityOrOfficeMaintenanceRepository.GetAllPseudoCityOrOfficeMaintenanceClientSubUnits(pseudoCityOrOfficeMaintenance.PseudoCityOrOfficeMaintenanceId);

            //CubaPseudoCityOrOfficeFlagNonNullable
            //Only a user with the Compliance Administrator for All Clients Globally and a GDS Administrator role (Global or Global Region or Country) can check or uncheck this box
            ViewData["ComplianceAdministratorAccess"] = "";
            if (rolesRepository.PseudoCityOrOfficeMaintenance_CubaPseudoCityOrOfficeFlag())
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //GovernmentPseudoCityOrOfficeFlagNonNullable
            //Only a user with the GDS Government Administrator role (Global or Global Region or Country) can check or uncheck this box
            ViewData["GDSGovernmentAdministratorAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess("GDS Government Administrator"))
            {
                ViewData["GDSGovernmentAdministratorAccess"] = "WriteAccess";
            }

            return(View(pseudoCityOrOfficeMaintenanceVM));
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Get Item
            GDSOrder gdsOrder = new GDSOrder();

            gdsOrder = gdsOrderRepository.GetGDSOrder(id);

            //Check Exists
            if (gdsOrder == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Empty list for dropdowns populated by Ajax
            List <SelectListItem> blankList = new List <SelectListItem>();

            GDSOrderVM GDSOrderVM = new GDSOrderVM();

            //Order Analyst
            GDSOrderAnalyst gdsOrderAnalyst = gdsOrderRepository.GetGDSOrderAnalyst();

            if (gdsOrderAnalyst != null)
            {
                gdsOrder.OrderAnalystName        = gdsOrderAnalyst.FirstName + " " + gdsOrderAnalyst.LastName;
                gdsOrder.OrderAnalystEmail       = gdsOrderAnalyst.Email;
                gdsOrder.OrderAnalystPhone       = gdsOrderAnalyst.Phone;
                gdsOrder.OrderAnalystCountryCode = gdsOrderAnalyst.CountryCode;
            }

            gdsOrderRepository.EditForDisplay(gdsOrder);

            PseudoCityOrOfficeMaintenanceRepository pseudoCityOrOfficeMaintenanceRepository = new PseudoCityOrOfficeMaintenanceRepository();

            pseudoCityOrOfficeMaintenanceRepository.EditForDisplay(gdsOrder.PseudoCityOrOfficeMaintenance);

            GDSOrderVM.GDSOrder = gdsOrder;

            //Select Lists
            GDSOrderVM.OrderAnalystCountries = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName", gdsOrder.OrderAnalystCountryCode);
            GDSOrderVM.RequesterCountries    = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName", gdsOrder.RequesterCountryCode);
            GDSOrderVM.GDSs                        = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName", gdsOrder.GDSCode);
            GDSOrderVM.GDSOrderTypes               = new SelectList(gdsOrderTypeRepository.GetAllGDSOrderTypes().ToList(), "GDSOrderTypeId", "GDSOrderTypeName", gdsOrder.GDSOrderTypeId);
            GDSOrderVM.GDSOrderStatuses            = new SelectList(gdsOrderStatusRepository.GetAllGDSOrderStatuses().ToList(), "GDSOrderStatusId", "GDSOrderStatusName", gdsOrder.GDSOrderStatusId);
            GDSOrderVM.PseudoCityOrOfficeAddresses = new SelectList(pseudoCityOrOfficeAddressRepository.GetUserPseudoCityOrOfficeAddresses().ToList(), "PseudoCityOrOfficeAddressId", "FirstAddressLine");
            GDSOrderVM.GDSOrderLineItemActions     = new SelectList(gdsOrderLineItemActionRepository.GetAllGDSOrderLineItemActions().ToList(), "GDSOrderLineItemActionId", "GDSOrderLineItemActionName");

            //ThirdPartyVendors
            GDSThirdPartyVendorRepository gdsThirdPartyVendorRepository = new GDSThirdPartyVendorRepository();

            GDSOrderVM.GDSThirdPartyVendors = gdsThirdPartyVendorRepository.GetAllGDSThirdPartyVendors();

            List <SelectListItem> gdsThirdPartyVendors = new List <SelectListItem>();

            foreach (GDSThirdPartyVendor gdsThirdPartyVendor in GDSOrderVM.GDSThirdPartyVendors)
            {
                gdsThirdPartyVendors.Add(
                    new SelectListItem
                {
                    Value = gdsThirdPartyVendor.GDSThirdPartyVendorId.ToString(),
                    Text  = gdsThirdPartyVendor.GDSThirdPartyVendorName.ToString()
                }
                    );
            }

            //GDS Order - ThirdPartyVendors
            List <GDSThirdPartyVendor> selectedGDSThirdPartyVendors = gdsOrderRepository.GetGDSOrderThirdPartyVendors(gdsOrder.GDSOrderId);

            GDSOrderVM.GDSThirdPartyVendorsList = new MultiSelectList(
                gdsThirdPartyVendors,
                "Value",
                "Text",
                selectedGDSThirdPartyVendors.Select(x => x.GDSThirdPartyVendorId).ToArray()
                );

            //IATAs
            IATARepository iataRepository = new IATARepository();

            GDSOrderVM.IATAs = new SelectList(iataRepository.GetAllIATAs().ToList(), "IATAId", "IATANumber");

            //GDSs
            GDSRepository GDSRepository = new GDSRepository();

            GDSOrderVM.GDSs = new SelectList(GDSRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            //PseudoCityOrOfficeDefinedRegions
            PseudoCityOrOfficeDefinedRegionRepository pseudoCityOrOfficeDefinedRegionRepository = new PseudoCityOrOfficeDefinedRegionRepository();

            GDSOrderVM.PseudoCityOrOfficeDefinedRegions = new SelectList(
                pseudoCityOrOfficeDefinedRegionRepository.GetPseudoCityOrOfficeDefinedRegionsForGlobalRegionCode(gdsOrder.PseudoCityOrOfficeMaintenance.GlobalRegionCode),
                "PseudoCityOrOfficeDefinedRegionId",
                "PseudoCityOrOfficeDefinedRegionName",
                gdsOrder.PseudoCityOrOfficeMaintenance.PseudoCityOrOfficeDefinedRegionId
                );

            //ExternalNames
            ExternalNameRepository externalNameRepository = new ExternalNameRepository();

            GDSOrderVM.ExternalNames = new SelectList(externalNameRepository.GetAllExternalNames().ToList(), "ExternalNameId", "ExternalName1");

            //PseudoCityOrOfficeTypes
            PseudoCityOrOfficeTypeRepository pseudoCityOrOfficeTypeRepository = new PseudoCityOrOfficeTypeRepository();

            GDSOrderVM.PseudoCityOrOfficeTypes = new SelectList(pseudoCityOrOfficeTypeRepository.GetAllPseudoCityOrOfficeTypes().ToList(), "PseudoCityOrOfficeTypeId", "PseudoCityOrOfficeTypeName");

            //PseudoCityOrOfficeLocationTypes
            PseudoCityOrOfficeLocationTypeRepository pseudoCityOrOfficeLocationTypeRepository = new PseudoCityOrOfficeLocationTypeRepository();

            GDSOrderVM.PseudoCityOrOfficeLocationTypes = new SelectList(pseudoCityOrOfficeLocationTypeRepository.GetAllPseudoCityOrOfficeLocationTypes().ToList(), "PseudoCityOrOfficeLocationTypeId", "PseudoCityOrOfficeLocationTypeName");

            //FareRedistributions
            FareRedistributionRepository fareRedistributionRepository = new FareRedistributionRepository();

            GDSOrderVM.FareRedistributions = new SelectList(
                fareRedistributionRepository.GetFareRedistributionsByGDSCode(gdsOrder.PseudoCityOrOfficeMaintenance.GDSCode),
                "FareRedistributionId",
                "FareRedistributionName",
                gdsOrder.PseudoCityOrOfficeMaintenance.FareRedistributionId
                );

            //CubaPseudoCityOrOfficeFlagNonNullable
            //Only a user with the Compliance Administrator for All Clients Globally and a GDS Administrator role (Global or Global Region or Country) can check or uncheck this box
            ViewData["ComplianceAdministratorAccess"] = "";
            if (rolesRepository.PseudoCityOrOfficeMaintenance_CubaPseudoCityOrOfficeFlag())
            {
                ViewData["ComplianceAdministratorAccess"] = "WriteAccess";
            }

            //GovernmentPseudoCityOrOfficeFlagNonNullable
            //Only a user with the GDS Government Administrator role (Global or Global Region or Country) can check or uncheck this box
            ViewData["GDSGovernmentAdministratorAccess"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess("GDS Government Administrator"))
            {
                ViewData["GDSGovernmentAdministratorAccess"] = "WriteAccess";
            }

            //PseudoCityOrOfficeMaintenance GDSThirdPartyVendors
            List <GDSThirdPartyVendor> selectedPseudoCityOrOfficeMaintenanceGDSThirdPartyVendors = gdsThirdPartyVendorRepository.GetGDSThirdPartyVendorsByPseudoCityOrOfficeMaintenanceId(
                gdsOrder.PseudoCityOrOfficeMaintenance.PseudoCityOrOfficeMaintenanceId
                );

            GDSOrderVM.PseudoCityOrOfficeMaintenanceGDSThirdPartyVendorsList = new MultiSelectList(
                gdsThirdPartyVendors,
                "Value",
                "Text",
                selectedPseudoCityOrOfficeMaintenanceGDSThirdPartyVendors.Select(x => x.GDSThirdPartyVendorId).ToArray()
                );

            return(View(GDSOrderVM));
        }