Exemple #1
0
        public void BindDDLs(PhysicalEntityView physicalEntityView, ObjectContext db)
        {
            //countries ddl
            ICountriesRepository countriesRepository = new CountriesRepository(db);

            physicalEntityView.Citizenships             = new SelectList(countriesRepository.GetCitizenships().ToList(), "CountryPK", "Citizenship");
            physicalEntityView.BirthCountries           = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");
            physicalEntityView.ResidenceCountries       = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");
            physicalEntityView.PassportCountriesOfIssue = new SelectList(countriesRepository.GetValid().OrderBy("Name ASC").ToList(), "CountryPK", "Name");

            //counties ddl
            if (physicalEntityView.BirthCountryFK != null)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                physicalEntityView.BirthCounties = new SelectList(countiesRepository.GetCountiesByCountry(Convert.ToInt32(physicalEntityView.BirthCountryFK)), "CountyPK", "Name", physicalEntityView.BirthCountyFK);
            }
            else
            {
                physicalEntityView.BirthCounties = new SelectList(new List <County>(), "CountyPK", "Name");
            }

            if (physicalEntityView.ResidenceCountryFK != null)
            {
                ICountiesRepository countiesRepository = new CountiesRepository(db);
                physicalEntityView.ResidenceCounties = new SelectList(countiesRepository.GetCountiesByCountry(Convert.ToInt32(physicalEntityView.ResidenceCountryFK)), "CountyPK", "Name", physicalEntityView.ResidenceCountyFK);
            }
            else
            {
                physicalEntityView.ResidenceCounties = new SelectList(new List <County>(), "CountyPK", "Name");
            }

            //citiesCommunities ddl
            if (physicalEntityView.BirthCountyFK != null)
            {
                ICitiesCommunitiesRepository citiesCommunitiesRepository = new CitiesCommunitiesRepository(db);
                physicalEntityView.BirthCitiesCommunities = new SelectList(citiesCommunitiesRepository.GetCitiesCommunitiesByCounty(Convert.ToInt32(physicalEntityView.BirthCountyFK)), "CityCommunityPK", "Name", physicalEntityView.BirthCityCommunityFK);
            }
            else
            {
                physicalEntityView.BirthCitiesCommunities = new SelectList(new List <CityCommunity>(), "CityCommunityPK", "Name");
            }

            if (physicalEntityView.ResidenceCountyFK != null)
            {
                ICitiesCommunitiesRepository citiesCommunitiesRepository = new CitiesCommunitiesRepository(db);
                physicalEntityView.ResidenceCitiesCommunities = new SelectList(citiesCommunitiesRepository.GetCitiesCommunitiesByCounty(Convert.ToInt32(physicalEntityView.ResidenceCountyFK)), "CityCommunityPK", "Name", physicalEntityView.ResidenceCityCommunityFK);
            }
            else
            {
                physicalEntityView.ResidenceCitiesCommunities = new SelectList(new List <CityCommunity>(), "CityCommunityPK", "Name");
            }

            //postal offices
            if (physicalEntityView.ResidenceCountyFK != null)
            {
                IPostalOfficesRepository postalOfficesRepository = new PostalOfficesRepository(db);
                var postalOffices = postalOfficesRepository.GetValidByCounty(Convert.ToInt32(physicalEntityView.ResidenceCountyFK)).OrderBy(c => c.Name);

                physicalEntityView.ResidencePostalOffices = new SelectList(postalOffices.Select(c => new { value = c.PostalOfficePK, text = c.Name + " (" + SqlFunctions.StringConvert((double)c.Number).Trim() + ")" }), "value", "text", physicalEntityView.ResidencePostalOfficeFK);
            }
            else
            {
                physicalEntityView.ResidencePostalOffices = new SelectList(new List <PostalOffice>(), "PostalOfficePK", "Name");
            }

            //places
            if (physicalEntityView.ResidencePostalOfficeFK != null)
            {
                IPlacesRepository placesRepository = new PlacesRepository(db);
                physicalEntityView.ResidencePlaces = new SelectList(placesRepository.GetPlacesByPostalOffice(Convert.ToInt32(physicalEntityView.ResidencePostalOfficeFK)), "PlacePK", "Name", physicalEntityView.ResidencePlaceFK);
            }
            else
            {
                physicalEntityView.ResidencePlaces = new SelectList(new List <Place>(), "PlacePK", "Name");
            }

            //regional offices ddl
            IRegionalOfficesRepository regionalOfficesView = new RegionalOfficesRepository(db);

            physicalEntityView.IdentityCardRegionalOffices = new SelectList(regionalOfficesView.GetValid().ToList(), "RegionalOfficePK", "Name", physicalEntityView.IdentityCardRegionalOfficeFK);
            physicalEntityView.ReferentRegionalOffices     = new SelectList(regionalOfficesView.GetValid().ToList(), "RegionalOfficePK", "Name", physicalEntityView.ReferentRegionalOfficeFK);

            //substations
            if (physicalEntityView.ReferentRegionalOfficeFK != null)
            {
                ISubstationsRepository substationsRepository = new SubstationsRepository(db);
                physicalEntityView.ReferentSubstations = new SelectList(substationsRepository.GetValidByRegionalOffice(Convert.ToInt32(physicalEntityView.ReferentRegionalOfficeFK)), "SubstationPK", "Name", physicalEntityView.ReferentSubstationFK);
            }
            else
            {
                physicalEntityView.ReferentSubstations = new SelectList(new List <Place>(), "SubstationPK", "Name");
            }

            // genders dll
            physicalEntityView.Genders = new SelectList(GeneratorView.GenerateGenders(), "Value", "Text");
        }