コード例 #1
0
 public async Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
 {
     return await Task.Run<MasterDataImportResponse>(async () =>
     {
         var vResults = new MasterDataImportResponse();
         var dtos = await ConstructDtOs(imports);
         int index = 1;
         foreach (var dto in dtos)
         {
             var res = await MapAndValidate(dto, index);
             if (res.IsValid)
             {
                 var dist = res.Entity as Distributor;
                var id= _repository.Save(dist, true);
                 AddUser(dist.Name.Replace("-", "") + "User", id, UserType.WarehouseManager, Guid.Empty);
                AddDistributorPendingDispatchWarehouse(id, dist.Name);
             }
             vResults.ValidationResults.Add(res);
             index++;
         }
         if (validationResultInfos.Any())
         {
             vResults.ValidationResults.AddRange(validationResultInfos);
             validationResultInfos.Clear();
         }
         return vResults;
     });
 }
コード例 #2
0
        public async Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return await Task.Run<MasterDataImportResponse>(async () =>
            {
                var vResults = new MasterDataImportResponse();
                var dtos = await ConstructDtOs(imports);
                int index = 1;
                foreach (var dto in dtos)
                {
                    var res = await MapAndValidate(dto, index);
                    if (res.IsValid)
                    {
                        _repository.Save(res.Entity as ProductPackagingType, true);
                    }
                    vResults.ValidationResults.Add(res);
                    index++;
                }
                if (validationResultInfos.Any())
                {
                    vResults.ValidationResults.AddRange(validationResultInfos);
                    validationResultInfos.Clear();
                }

                return vResults;
            });
        }
コード例 #3
0
 public async Task<MasterDataImportResponse> ValidateAsync(IEnumerable<ImportEntity> imports)
 {
     return await Task.Run(async () =>
     {
         var vResults = new MasterDataImportResponse();
         var dtos = await ConstructDtOs(imports);
         int index = 1;
         foreach (var dto in dtos)
         {
             var res = await MapAndValidate(dto, index);
             vResults.ValidationResults.Add(res);
             index++;
         }
         return vResults;
     });
 }
コード例 #4
0
        public async Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return await  Task.Run<MasterDataImportResponse>(async () =>
            {
                var vResults = new MasterDataImportResponse();
                var dtos = await ConstructSalesmanDtOs(imports);
                int index = 1;
                var savedSalesmen = new List<DistributorSalesman>();
                foreach (var dto in dtos)
                {
                    var res = await MapAndValidate(dto, index);
                    if (res.IsValid)
                    {
                        var entity = res.Entity as DistributorSalesman;
                        if(HasSalesmanChanged(entity))
                        _repository.Save(entity, true);
                        savedSalesmen.Add(entity);
                    }
                    vResults.ValidationResults.Add(res);
                    index++;
                }
                var users = ConstructUsers(savedSalesmen);
                if(users.Any())
                {
                    var validatedUsers = ValidateUsers(users).ToList();
                    var valid = validatedUsers.Where(p => p.IsValid).Select(p => p.Entity).ToList();
                    if (valid.Any())
                    {
                        valid.ForEach(n => _userRepository.Save((User)n, true));
                    }
                    vResults.ValidationResults.AddRange(validatedUsers.Where(p=>!p.IsValid).ToList());

                }
                if (validationResultInfos.Any())
                {
                    vResults.ValidationResults.AddRange(validationResultInfos);
                    validationResultInfos.Clear();
                }
                return vResults;
            });
        }
コード例 #5
0
        public async Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return await Task.Run<MasterDataImportResponse>(async () =>
            {
                var vResults = new MasterDataImportResponse();
                var dtos = await ConstructDtOs(imports);
                int index = 1;
                foreach (var dto in dtos)
                {
                    var res = await MapAndValidate(dto, index);
                    if (res.IsValid)
                    {
                        _territoryRepository.Save(res.Entity as Territory, true);
                    }
                    vResults.ValidationResults.Add(res);
                    index++;
                }

                return vResults;
            });
        }
コード例 #6
0
        public Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return Task.Run(() =>
                                {
                                    var response = new MasterDataImportResponse();
                                    var importEntities = imports as List<ImportEntity> ?? imports.ToList();
                                    int batchSize = Convert.ToInt32(0.2*importEntities.Count());
                                    var productImports =
                                        Enumerable.Select<IEnumerable<ImportEntity>, List<ImportEntity>>(importEntities.OrderBy(p => p.MasterDataCollective).Batch(batchSize), x => Enumerable.ToList<ImportEntity>(x)).ToList();
                                    validationResultInfos.Clear();

                                    #region Construct Pricings

                                    var pricingTaskArray = new Task<ProductPricingDTO[]>[productImports.Count];
                                    var results = new List<ProductPricingDTO>();
                                    try
                                    {
                                        for (int i = 0; i < pricingTaskArray.Length; i++)
                                        {
                                            var current = productImports.FirstOrDefault();
                                            if (current != null && current.Any())
                                            {
                                                pricingTaskArray[i] =
                                                    Task<ProductPricingDTO[]>.Factory.StartNew(
                                                        () => ConstructDtOs(current));
                                                productImports.Remove(current);
                                            }
                                        }

                                        foreach (var result in pricingTaskArray.Select(n => n.Result).ToList())
                                        {
                                            results.AddRange(result);
                                        }
                                    }
                                    catch (AggregateException ex)
                                    {
                                    }

                                    #endregion

                                    #region validate pricings
                                    var validationResults = new List<ImportValidationResultInfo>();
                                    if (validationResultInfos.Any())
                                    {
                                        validationResults.AddRange(validationResultInfos);
                                        validationResultInfos.Clear();
                                    }
                                    if (results.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*results.Count);
                                        var productPricings =
                                            results.OrderBy(p => p.SellingPrice).Batch(batchSize).Select(
                                                x => x.ToList()).ToList();
                                        var validationTaskArray =
                                            new Task<ImportValidationResultInfo[]>[productPricings.Count];

                                        try
                                        {
                                            for (int i = 0; i < validationTaskArray.Length; i++)
                                            {
                                                var current = productPricings.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    validationTaskArray[i] =
                                                        Task<ImportValidationResultInfo[]>.Factory.StartNew(
                                                            () => MapAndValidate(current));
                                                    productPricings.Remove(current);
                                                }
                                            }

                                            foreach (var result in validationTaskArray.Select(n => n.Result).ToList())
                                            {
                                                validationResults.AddRange(result);
                                            }
                                        }
                                        catch (AggregateException ex)
                                        {
                                        }

                                    }

                                    #endregion

                                    #region Save pricings

                                    var validatedPricings =
                                        validationResults.Where(n => n.Entity is ProductPricing && n.IsValid).Select
                                            (n => (ProductPricing) n.Entity).ToList();
                                    if (validatedPricings.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*validatedPricings.Count);
                                        var pricings =
                                            validatedPricings.OrderBy(p => p.CurrentEffectiveDate).Batch(batchSize).
                                                Select(x => x.ToList()).ToList();

                                        var saveTasksArray = new Task<Guid[]>[pricings.Count];
                                        try
                                        {
                                            for (int i = 0; i < saveTasksArray.Length; i++)
                                            {
                                                var current = pricings.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    saveTasksArray[i] =
                                                        Task<Guid[]>.Factory.StartNew(() => SaveProductPricings(current));
                                                    pricings.Remove(current);
                                                }
                                            }
                                            var savedResults = new List<Guid>();
                                            foreach (var result in saveTasksArray.Select(n => n.Result).ToList())
                                            {
                                                savedResults.AddRange(result);
                                            }
                                        }
                                        catch (AggregateException ex)
                                        {
                                        }
                                    }

                                    #endregion

                                    response.ValidationResults = validationResults;

                                    return response;
                                });
        }
コード例 #7
0
        public Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return Task.Run(() =>
                                {
                                    var response = new MasterDataImportResponse();
                                    var importEntities = imports as List<ImportEntity> ?? imports.ToList();
                                    int batchSize = Convert.ToInt32(0.2*importEntities.Count());
                                    var outletImports =
                                        Enumerable.Select<IEnumerable<ImportEntity>, List<ImportEntity>>(importEntities.OrderBy(p => p.MasterDataCollective).Batch(batchSize), x => Enumerable.ToList<ImportEntity>(x)).ToList();
                                  validationResultInfos.Clear();

                                    #region Construct Items

                                    var taskArray = new Task<tblShipToAddress[]>[outletImports.Count];
                                    var results = new List<tblShipToAddress>();
                                    try
                                    {
                                        for (int i = 0; i < taskArray.Length; i++)
                                        {
                                            var current = outletImports.FirstOrDefault();
                                            if (current != null && current.Any())
                                            {
                                                taskArray[i] =
                                                    Task<tblShipToAddress[]>.Factory.StartNew(
                                                        () => ConstructDtOs(current));
                                                outletImports.Remove(current);
                                            }
                                        }
                                        foreach (var result in taskArray.Select(n => n.Result).ToList())
                                        {
                                            results.AddRange(result);
                                        }
                                    }
                                    catch (AggregateException ex)
                                    {
                                        foreach (var error in ex.InnerExceptions)
                                        {
                                            response.ErrorInfo += error;
                                        }

                                    }
                                    var validationResults = new List<ImportValidationResultInfo>();
                                    if (validationResultInfos.Any())
                                    {
                                        validationResults.AddRange(validationResultInfos);
                                        validationResultInfos.Clear();
                                    }

                                    #endregion

                                    #region Save valid items

                                    var validatedAddresses = results;
                                    if (validatedAddresses.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*validatedAddresses.Count);
                                        var outlets =
                                            validatedAddresses.OrderBy(p => p.Name).Batch(batchSize).Select(
                                                x => x.ToList()).ToList();

                                        var saveTasksArray = new Task<int>[outlets.Count];
                                        try
                                        {
                                            for (int i = 0; i < saveTasksArray.Length; i++)
                                            {
                                                var current = outlets.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    saveTasksArray[i] =
                                                        Task<int>.Factory.StartNew(() => MapAndInsert(current));
                                                    outlets.Remove(current);
                                                }
                                            }
                                            var savedResults = saveTasksArray.Select(n => n.Result).ToList().ToList();
                                        }
                                        catch (AggregateException ex)
                                        {
                                            foreach (var error in ex.InnerExceptions)
                                            {
                                                response.ErrorInfo += error;
                                            }
                                        }
                                    }



                                    #endregion

                                    response.ValidationResults.AddRange(validationResults);

                                    return response;
                                });

        }
コード例 #8
0
        public Task<MasterDataImportResponse> ValidateAndSaveAsync(IEnumerable<ImportEntity> imports)
        {
            return Task.Run(() =>
                                {
                                    var response = new MasterDataImportResponse();
                                    var importEntities = imports as List<ImportEntity> ?? imports.ToList();
                                    int batchSize = Convert.ToInt32(0.2*importEntities.Count());
                                    var outletImports =
                                        Enumerable.Select<IEnumerable<ImportEntity>, List<ImportEntity>>(importEntities.OrderBy(p => p.MasterDataCollective).Batch(batchSize), x => Enumerable.ToList<ImportEntity>(x)).ToList();
                                   
                                    #region Construct Items

                                    var taskArray = new Task<OutletDTO[]>[outletImports.Count];
                                    var results = new List<OutletDTO>();
                                    try
                                    {
                                        for (int i = 0; i < taskArray.Length; i++)
                                        {
                                            var current = outletImports.FirstOrDefault();
                                            if (current != null && current.Any())
                                            {
                                                taskArray[i] =
                                                    Task<OutletDTO[]>.Factory.StartNew(
                                                        () => ConstructDtOs(current));
                                                outletImports.Remove(current);
                                            }
                                        }
                                        foreach (var result in taskArray.Select(n => n.Result).ToList())
                                        {
                                            results.AddRange(result);
                                        }
                                    }
                                    catch (AggregateException ex)
                                    {
                                        foreach (var error in ex.InnerExceptions)
                                        {
                                            response.ErrorInfo += error;
                                        }

                                    }

                                    #endregion

                                    #region Validate Items

                                    var validationResults = new List<ImportValidationResultInfo>();
                                    if (validationResultInfos.Any())
                                    {
                                        validationResults.AddRange(validationResultInfos);
                                        validationResultInfos.Clear();
                                    }
                                    
                                    if (results.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*results.Count);
                                        var outlets =
                                            results.OrderBy(p => p.CostCentreCode).Distinct().Batch(batchSize).Select(
                                                x => x.ToList()).
                                                ToList();
                                        var validationTaskArray = new Task<ImportValidationResultInfo[]>[outlets.Count];


                                        try
                                        {
                                            for (int i = 0; i < validationTaskArray.Length; i++)
                                            {
                                                var current = outlets.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    validationTaskArray[i] =
                                                        Task<ImportValidationResultInfo[]>.Factory.StartNew(
                                                            () => MapAndValidate(current));
                                                    outlets.Remove(current);
                                                }
                                            }

                                            foreach (var result in validationTaskArray.Select(n => n.Result).ToList())
                                            {
                                                validationResults.AddRange(result);
                                            }
                                        }
                                        catch (AggregateException ex)
                                        {
                                            foreach (var error in ex.InnerExceptions)
                                            {
                                                response.ErrorInfo += error;
                                            }
                                        }

                                    }

                                    #endregion

                                    #region Save valid items

                                    var validatedOutlets =
                                        validationResults.Where(n => n.IsValid).Select(n => (Outlet) n.Entity).
                                            ToList();
                                    if (validatedOutlets.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*validatedOutlets.Count);
                                        var outlets =
                                            validatedOutlets.OrderBy(p => p.CostCentreCode).Batch(batchSize).Select(
                                                x => x.ToList()).ToList();

                                        var saveTasksArray = new Task<Guid[]>[outlets.Count];
                                        try
                                        {
                                            for (int i = 0; i < saveTasksArray.Length; i++)
                                            {
                                                var current = outlets.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    saveTasksArray[i] =
                                                        Task<Guid[]>.Factory.StartNew(() => SaveItems(current));
                                                    outlets.Remove(current);
                                                }
                                            }
                                            var savedResults = new List<Guid>();
                                            foreach (var result in saveTasksArray.Select(n => n.Result).ToList())
                                            {
                                                savedResults.AddRange(result);
                                            }

                                        }
                                        catch (AggregateException ex)
                                        {
                                            foreach (var error in ex.InnerExceptions)
                                            {
                                                response.ErrorInfo += error;
                                            }
                                        }
                                    }



                                    #endregion

                                    response.ValidationResults.AddRange(validationResults);
                                   
                                    foreach (var result in response.ValidationResults)
                                    {
                                        result.Entity = null;
                                        result.EntityItem = "Outlet";
                                    }
                                  
                                    return response;
                                });


        }
コード例 #9
0
        public Task<MasterDataImportResponse> ValidateAsync(IEnumerable<ImportEntity> imports)
        {
            return Task.Run(() =>
                                {
                                    var response = new MasterDataImportResponse();
                                    var importEntities = imports as List<ImportEntity> ??
                                                         imports.ToList();
                                    int batchSize = Convert.ToInt32(0.2*importEntities.Count()); //batch 20% of the collection and process in parallel
                                    var brandImports =
                                        Enumerable.Select<IEnumerable<ImportEntity>, List<ImportEntity>>(importEntities.OrderBy(p => p.MasterDataCollective).
                                                Batch(batchSize), x => Enumerable.ToList<ImportEntity>(x)).ToList();

                                    #region Construct Items

                                    var taskArray =
                                        new Task<ProductBrandDTO[]>[brandImports.Count];
                                    var results = new List<ProductBrandDTO>();
                                    try
                                    {
                                        for (int i = 0; i < taskArray.Length; i++)
                                        {
                                            var current = brandImports.FirstOrDefault();
                                            if (current != null && current.Any())
                                            {
                                                taskArray[i] =
                                                    Task<ProductBrandDTO[]>.Factory.StartNew(
                                                        () => ConstructDtOs(current));
                                                brandImports.Remove(current);
                                            }
                                        }

                                        foreach (
                                            var result in
                                                taskArray.Select(n => n.Result).ToList())
                                        {
                                            results.AddRange(result);
                                        }
                                    }
                                    catch (AggregateException ex)
                                    {
                                        foreach (var error in ex.InnerExceptions)
                                        {
                                            response.ErrorInfo += error;
                                        }

                                    }

                                    #endregion

                                    #region Validate Items

                                 var validationResults = new List<ImportValidationResultInfo>();
                                    if (validationResultInfos.Any())
                                    {
                                        validationResults.AddRange(validationResultInfos);
                                        validationResultInfos.Clear();
                                    }
                                    if (results.Any())
                                    {
                                        batchSize = Convert.ToInt32(0.2*results.Count);
                                        var brands =
                                            results.OrderBy(p => p.Code).Batch(batchSize).Select
                                                (x => x.ToList()).
                                                ToList();
                                        var validationTaskArray =
                                            new Task<ImportValidationResultInfo[]>[brands.Count];


                                        try
                                        {
                                            for (int i = 0; i < validationTaskArray.Length; i++)
                                            {
                                                var current = brands.FirstOrDefault();
                                                if (current != null && current.Any())
                                                {
                                                    validationTaskArray[i] =
                                                        Task<ImportValidationResultInfo[]>.
                                                            Factory.StartNew(
                                                                () => MapAndValidate(current));
                                                    brands.Remove(current);
                                                }
                                            }

                                            foreach (
                                                var result in
                                                    validationTaskArray.Select(n => n.Result).
                                                        ToList())
                                            {
                                                validationResults.AddRange(result);
                                            }
                                        }
                                        catch (AggregateException ex)
                                        {
                                            foreach (var error in ex.InnerExceptions)
                                            {
                                                response.ErrorInfo += error;
                                            }
                                        }

                                    }

                                    #endregion

                                    response.ValidationResults.AddRange(validationResults);
                                    foreach (var result in response.ValidationResults)
                                    {
                                        result.Entity = new ProductBrand(Guid.Empty);
                                    }
                                    return response;
                                });
        }