Beispiel #1
0
 /// <remarks/>
 public void GetPartyByGTINAsync(GetPartyByGTIN GetPartyByGTIN1) {
     this.GetPartyByGTINAsync(GetPartyByGTIN1, null);
 }
Beispiel #2
0
 /// <remarks/>
 public void GetPartyByGTINAsync(GetPartyByGTIN GetPartyByGTIN1, object userState) {
     if ((this.GetPartyByGTINOperationCompleted == null)) {
         this.GetPartyByGTINOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetPartyByGTINOperationCompleted);
     }
     this.InvokeAsync("GetPartyByGTIN", new object[] {
                 GetPartyByGTIN1}, this.GetPartyByGTINOperationCompleted, userState);
 }
        public Product GetProduct(string gtin)
        {
            var gepirProductService = WebServiceFactory.CreateProductServiceProxy();

            var mappedProduct = new Product
                                    {GlobalTradeItemNumber = gtin, LastUpdated = DateTime.Now};

            try
            {
                var paddedGtin = gtin.PadLeft(14, '0');
                var getItemByGtin = new GetItemByGTIN { requestedGtin = paddedGtin, versionSpecified = false };
                var itemByGtin = gepirProductService.GetItemByGTIN(getItemByGtin);

                // If request ok (return code 0) and product found
                if (gepirProductService.gepirResponseHeaderValue.returnCode == 0
                    && itemByGtin != null
                    && itemByGtin.itemDataLine != null
                    && itemByGtin.itemDataLine.Length > 0)
                {
                    var gepirProduct = itemByGtin.itemDataLine[0];

                    //TODO Sometimes leads to NotSupportedException - Adding/Attaching an item that is not new
                    //UpdateDomain(gepirProductService, gtin, gepirProduct);
                    //mappedProduct = _productDomainService.FindProductByGtin(gtin, true);

                    mappedProduct = _gepirProductMapper.Map(gepirProduct);
                }
                // If the product couldn't be found we can still get the GTIN owner
                else
                {
                    var getPartyByGtin = new GetPartyByGTIN() { requestedGtin = new[] { paddedGtin }, versionSpecified = false };
                    var partyByGtin = gepirProductService.GetPartyByGTIN(getPartyByGtin);
                    var brand = new Brand {LastUpdated = DateTime.Now};
                    if (gepirProductService.gepirResponseHeaderValue.returnCode == 0 
                        && partyByGtin != null 
                        && partyByGtin.partyDataLine != null 
                        && partyByGtin.partyDataLine.Length > 0)
                    {
                        //using (var companyRepository = _repositoryFactory.Build<IRepository<Company>, Company>())
                        //{
                            var gepirCompany = partyByGtin.partyDataLine[0];
                            Company company = null;
                            var matchingCompanies = _companyRepository.Find(x => x.CompanyName == gepirCompany.partyName);
                            if (!matchingCompanies.Any())
                            {
                                company = _gepirCompanyMapper.Map(gepirCompany);
                                _companyRepository.Add(company);
                                _companyRepository.Persist();
                            }
                            else if (matchingCompanies.Count() == 1)
                            {
                                company = matchingCompanies.First();
                            }
                            brand.Owner = company;
                            mappedProduct.Brand = brand;
                        //}
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("Gepir router threw an exception.", exception);
                if (gepirProductService.gepirResponseHeaderValue != null)
                {
                    Log.Error("Gepir returnCode:", gepirProductService.gepirResponseHeaderValue.returnCode);
                }
                return null;
            }

            return mappedProduct;
        }