public async void CreateAddress(Company company, LegalAddressViewModel model)
        {
            Address legalAddress = new Address {
                CountryId = model.CountryId, City = model.City, PostCode = model.PostCode, Street = model.Street, HouseAddress = model.HouseAddress, CompanyId = company.Id, AddressType = AddressType.Create(AddressTypesEnum.LegalAddress)
            };
            await context.Addresses.AddAsync(legalAddress);

            context.SaveChanges();
        }
        public async void CreateAddress(UserInfo userInfo, LegalAddressViewModel model)
        {
            Address legalAddress = new Address {
                CountryId = model.CountryId, City = model.City, PostCode = model.PostCode, Street = model.Street, HouseAddress = model.HouseAddress, UserInfoId = userInfo.Id, AddressType = GetAddressType(AddressTypesEnum.LegalAddress)
            };
            await context.Addresses.AddAsync(legalAddress);

            context.SaveChanges();
        }
        public IActionResult Edit(int id)
        {
            Company                   company                   = companyService.GetCompanies().FirstOrDefault(c => c.Id == id);
            RegistrationData          registrationData          = companyService.FindRegistrationDataById(company.RegistrationDataId);
            CompanyViewModel          companyViewModel          = new CompanyViewModel(company);
            RegistrationDataViewModel registrationDataViewModel = new RegistrationDataViewModel(registrationData);
            FactAddressViewModel      factAddressViewModel      = new FactAddressViewModel();
            ContactInfoViewModel      contactInfoViewModel      = new ContactInfoViewModel
            {
                CityPhone   = company.ContactInfo.CityPhone,
                MobilePhone = company.ContactInfo.MobilePhone,
                Email       = company.ContactInfo.Email
            };
            Address factAddress = companyService.FindFactAddressByCompanyId(company.Id);

            if (factAddress != null)
            {
                factAddressViewModel.CountryId    = factAddress.CountryId;
                factAddressViewModel.City         = factAddress.City;
                factAddressViewModel.Street       = factAddress.Street;
                factAddressViewModel.HouseAddress = factAddress.HouseAddress;
                factAddressViewModel.PostCode     = factAddress.PostCode;
            }

            LegalAddressViewModel legalAddressViewModel = new LegalAddressViewModel();
            Address legalAddress = companyService.FindLegalAddressByCompanyId(company.Id);

            if (factAddress != null)
            {
                legalAddressViewModel.CountryId    = legalAddress.CountryId;
                legalAddressViewModel.City         = legalAddress.City;
                legalAddressViewModel.Street       = legalAddress.Street;
                legalAddressViewModel.HouseAddress = legalAddress.HouseAddress;
                legalAddressViewModel.PostCode     = legalAddress.PostCode;
            }

            CompanyEditViewModel model = new CompanyEditViewModel
            {
                FactAddress      = factAddressViewModel,
                LegalAddress     = legalAddressViewModel,
                Company          = companyViewModel,
                RegistrationData = registrationDataViewModel,
                ContactInfo      = contactInfoViewModel
            };

            model.Countries             = selectListService.GetCountries();
            model.LegalForms            = selectListService.GetLegalForms();
            model.PropertyTypes         = selectListService.GetPropertyTypes();
            model.Residencies           = selectListService.GetResidencies();
            model.TaxInspections        = selectListService.GetTaxInspections();
            ViewBag.CountriesForAddress = GetCountriesForAddress();

            return(View(model));
        }
 private LegalAddressViewModel countryUserEmpty(LegalAddressViewModel legalAddress, Address address)
 {
     if (legalAddress.CountryId == null)
     {
         legalAddress.CountryName = string.Empty;
     }
     else
     {
         legalAddress.CountryName = address.Country.CountryName;
     }
     return(legalAddress);
 }
        public Address AddressEdit(UserInfo user, LegalAddressViewModel model)
        {
            Address address = FindLegalAddressByUserInfoId(user.Id);

            address.PostCode     = model.PostCode;
            address.Street       = model.Street;
            address.HouseAddress = model.HouseAddress;
            address.CountryId    = model.CountryId;
            address.City         = model.City;
            context.Addresses.Update(address);
            context.SaveChanges();
            return(address);
        }