Exemple #1
0
        public async Task <ImportResult> ImportAsync(
            IEnumerable <Customer> insert,
            IEnumerable <Customer> update,
            IEnumerable <Customer> delete, CancellationToken token = default(CancellationToken))
        {
            using (var scope = transactionScopeBuilder.Create())
            {
                int deleteCount = 0;
                int updateCount = 0;
                int insertCount = 0;

                foreach (var x in delete)
                {
                    await deleteCustomerQueryProcessor.DeleteAsync(x.Id, token);

                    deleteCount++;
                }

                foreach (var x in update)
                {
                    await addCustomerQueryProcessor.SaveAsync(x, token : token);

                    if (x.CollectCategoryCode == "00")
                    {
                        var contract = x.GetContract();
                        await addCustomerPaymentContractQueryProcessor.SaveAsync(contract, token);
                    }
                    updateCount++;
                }

                foreach (var x in insert)
                {
                    var customer = await addCustomerQueryProcessor.SaveAsync(x, token : token);

                    x.Id = customer.Id;
                    if (x.CollectCategoryCode == "00")
                    {
                        var contract = x.GetContract();
                        await addCustomerPaymentContractQueryProcessor.SaveAsync(contract, token);
                    }
                    insertCount++;
                }

                scope.Complete();
                return(new ImportResult
                {
                    ProcessResult = new ProcessResult {
                        Result = true
                    },
                    InsertCount = insertCount,
                    UpdateCount = updateCount,
                    DeleteCount = deleteCount,
                });
            }
        }
Exemple #2
0
 public async Task <CustomerPaymentContract> SaveAsync(CustomerPaymentContract contract, CancellationToken token = default(CancellationToken))
 => await addCustomerPaymentContractQueryProcessor.SaveAsync(contract, token);