Exemplo n.º 1
0
        private MasterDataValidationAndImportResponse GenerateResponse(MasterDataImportResponse res)
        {
            var response=new MasterDataValidationAndImportResponse();
            if (res == null) return response;

            response.ValidationResults = res.ValidationResults
                .Select(n => new StringifiedValidationResult()
                                 {
                                     Results =
                                         n.Results.Select(
                                             p => p.ErrorMessage).ToList(),
                                     Entity = n.EntityItem,
                                     Description = n.Description,
                                     IsValid = n.IsValid
                                 }).ToList();
            response.UploadedItemsCount = res.ValidationResults.Count(n => n.IsValid);
           return response;


        }
       private async Task<MasterDataImportResponse> ImportEntity(List<ImportEntity> importData)
       {
           var response = new MasterDataImportResponse();
           var entityType = (MasterDataCollective)Enum.Parse(typeof(MasterDataCollective), importData.FirstOrDefault().MasterDataCollective);
           switch (entityType)
           {
               case MasterDataCollective.Territory:
                   response = await _territoryImportService.ValidateAndSaveAsync(importData);
                   
                   break;

               case MasterDataCollective.Country:
                   response = await _countryImportService.ValidateAndSaveAsync(importData);
                  break;

               case MasterDataCollective.Region:
                   response = await _regionImportService.ValidateAndSaveAsync(importData);
                
                   break;
               case MasterDataCollective.Area:
                   response = await _areaImportService.ValidateAndSaveAsync(importData);

                   break;

               case MasterDataCollective.AssetCategory:
                   response = await _assetCategoryImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.Bank:
                   response = await _bankImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.BankBranch:
                   response = await _bankBranchImportService.ValidateAndSaveAsync(importData);
                   break;

               case MasterDataCollective.ProductBrand:
                   response = await _productBrandImportService.ValidateAndSaveAsync(importData);
                  
                   break;
               case MasterDataCollective.VatClass:
                   response = await _vatClassImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.Supplier:
                   response = await _supplierImportService.ValidateAndSaveAsync(importData);
                   break;

               case MasterDataCollective.ProductFlavour:
                   response = await _productFlavourImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.ProductPackagingType:
                   response = await _productPackagingTypeImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.ProductType:
                   response = await _productTypeImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.PricingTier:
                   response = await _pricingTierImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.OutletCategory:
                   response = await _outletCategoryImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.OutletType:
                   response = await _outletTypeImportService.ValidateAndSaveAsync(importData);
                   break;
               
               case MasterDataCollective.ContactType:
                   response = await _contactTypeImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.Province:
                   response = await _provinceImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.District:
                   response = await _districtImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.SaleProduct:
                   response = await _saleProductImportService.ValidateAndSaveAsync(importData);
                   break;

               case MasterDataCollective.Pricing:
                   response = await _pricingImportService.ValidateAndSaveAsync(importData);
                   break;

               case MasterDataCollective.DiscountGroup:
                   response = await _discountGroupImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.PromotionDiscount:
                   response = await _promotionDiscountImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.ProductGroupDiscount:
                   response = await _productGroupDiscountImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.SaleValueDiscount:
                   response = await _saleValueDiscountImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.DistributorSalesman:
                   response =await  _salesmanImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.Outlet:
                   response = await _outletImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.Route:
                   response = await _routeImportService.ValidateAndSaveAsync(importData);
                   break;
               case MasterDataCollective.ProductPackaging:
                   response = await _productPackagingImportService.ValidateAndSaveAsync(importData);
                   break;
                   case MasterDataCollective.Distributor:
                   response = await _distributorsImportService.ValidateAndSaveAsync(importData);
                   break;

                   #region Agrimanagr
                   case MasterDataCollective.Commodity:
                   response = await _commodityImportService.ValidateAndSaveAsync(importData);
                   break;
                   case MasterDataCollective.CommodityType:
                   response = await _commodityTypeImportService.ValidateAndSaveAsync(importData);
                   break;
                   case MasterDataCollective.CommodityOwnerType:
                   response = await _commodityOwnerTypeImportService.ValidateAndSaveAsync(importData);
                   break;
                   case MasterDataCollective.CommodityOwner:
                   response = await _commodityOwnerImportService.ValidateAndSaveAsync(importData);
                   break;
                   case MasterDataCollective.CommoditySupplier:
                   response = await _commoditySupplierImportService.ValidateAndSaveAsync(importData);
                   break;
                   #endregion

                   default:
                   var shipto = importData.FirstOrDefault();
                   if (shipto != null && shipto.MasterDataCollective.Contains("shipto"))
                   {
                       response = await _shiptoAddressesImportService.ValidateAndSaveAsync(importData);
                   }
                   else
                   {
                       response.Result = "Success";
                       response.ResultInfo = "No entity to be imported";
                       response.ErrorInfo = "Success"; 
                   }
                   break;
           }
           int count = response.ValidationResults.Where(n => !n.IsValid).Count();
           response.ResultInfo = response.ValidationResults.Any(n => !n.IsValid) ? "Completed with errors" : "Success";
           response.Result = "success";
           return response;
       }