Beispiel #1
0
        public CompanyModel GetById(string id)
        {
            try
            {
                var company = new CompanyModel();
                switch (NipRegonValidator.IsValid(id))
                {
                case (int)NumberType.nip:
                    company = Mapper.Map <CompanyModel>(companyRepository.GetByNip(id));
                    break;

                case (int)NumberType.krs:
                    company = Mapper.Map <CompanyModel>(companyRepository.GetByKrs(id));
                    break;

                case (int)NumberType.regon:
                    company = Mapper.Map <CompanyModel>(companyRepository.GetByRegon(id));
                    break;
                }
                if (company == null)
                {
                    company = krsApiCommunicationService.GetCompanyById(id);
                    if (company?.Krs != null && company.Nip != null)
                    {
                        companyRepository.AddNewCompany(Mapper.Map <CompanyEntity>(company));
                        companyRepository.Save();
                    }
                }
                return(company);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Beispiel #2
0
        public CompanyModel GetCompanyById(string id)
        {
            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromMinutes(1);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    var company = new CompanyJsonModel();
                    switch (NipRegonValidator.IsValid(id))
                    {
                    case (int)NumberType.nip:
                        company = GetByNipAsync(client, id);
                        break;

                    case (int)NumberType.krs:
                        company = GetByRegonAsync(client, id);
                        break;

                    case (int)NumberType.regon:
                        company = GetByKrsAsync(client, id);
                        break;
                    }
                    return(Mapper.Map <CompanyModel>(company));
                }
                catch (HttpRequestException e)
                {
                    throw e;
                }
            }
        }