public async Task AddCompanyAsync(AddCompanyViewModel model) { var company = await _companyRepo.GetCompanyByNameAsync(model.Name); if (company != null) { throw new Exception("Firma już istnieje w bazie!"); } var office = await _officeRepo.GetPostOfficeByName(model.Name); var regions = await _regionRepo.GetRegionsAsync(); var region = regions.SingleOrDefault(x => x.PostOfficeId == office.OfficeId); company = new Company(region.RegionId, Guid.NewGuid(), model.Name, model.Adress, model.Longitude, model.Latitude, model.StartHour, model.FinishHour); await _companyRepo.AddCompanyAsync(company); }