public async Task <CompanyListModel> PrepareEditModal(Guid id) { var company = await _companyAppService.GetById(id); if (company == null) { throw new Exception("Id not found"); } var countries = await _countryAppService.GetAll(); var provinces = await _provinceAppService.GetAllByCountryId(company.CountryId); IEnumerable <SelectListItem> selectListCountry = countries.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); IEnumerable <SelectListItem> selectListProvince = provinces.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); selectListCountry.FirstOrDefault(x => x.Value == company.CountryId.ToString()).Selected = true; selectListProvince.FirstOrDefault(x => x.Value == company.ProvinceId.ToString()).Selected = true; List <CompanyDto> companyList = new List <CompanyDto>(); companyList.Add(company); var model = new CompanyListModel() { Companies = companyList, Countries = selectListCountry, Provinces = selectListProvince }; return(model); }
public async Task <CompanyListModel> PrepareCompanyModel() { var provinces = await _provinceAppService.GetAll(); var countries = await _countryAppService.GetAll(); var companies = await _companyAppService.GetAll(); IEnumerable <SelectListItem> selectListCountry = countries.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); IEnumerable <SelectListItem> selectListProvince = provinces.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); var model = new CompanyListModel() { Provinces = selectListProvince, Countries = selectListCountry, Companies = companies }; return(model); }