コード例 #1
0
        public async Task <int> CreateAsync(SalesReceiptModel model)
        {
            int result = 0;

            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    int index = 0;
                    foreach (var item in model.SalesReceiptDetails)
                    {
                        var updateToSalesInvoice = DbContext.SalesInvoices.FirstOrDefault(x => x.Id == item.SalesInvoiceId);
                        updateToSalesInvoice.TotalPaid = item.Paid;
                        updateToSalesInvoice.IsPaidOff = item.IsPaidOff;
                    }

                    do
                    {
                        model.Code = CodeGenerator.Generate();
                    }while (DbSet.Any(d => d.Code.Equals(model.Code)));

                    SalesReceiptNumberGenerator(model, index);
                    salesReceiptLogic.Create(model);
                    index++;

                    result = await DbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(result);
        }
コード例 #2
0
        public async Task <int> CreateAsync(SalesReceiptModel model)
        {
            int result = 0;

            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    int index = 0;
                    foreach (var item in model.SalesReceiptDetails)
                    {
                        SalesReceiptModel salesInvoice = new SalesReceiptModel()
                        {
                            Id               = model.Id,
                            Code             = model.Code,
                            AutoIncreament   = model.AutoIncreament,
                            SalesReceiptNo   = model.SalesReceiptNo,
                            SalesReceiptType = model.SalesReceiptType,
                            SalesReceiptDate = model.SalesReceiptDate,
                            BankId           = model.BankId,
                            AccountCOA       = model.AccountCOA,
                            AccountName      = model.AccountName,
                            AccountNumber    = model.AccountNumber,
                            BankName         = model.BankName,
                            BankCode         = model.BankCode,
                            BuyerId          = model.BuyerId,
                            BuyerName        = model.BuyerName,
                            BuyerAddress     = model.BuyerAddress,

                            Active            = model.Active,
                            CreatedAgent      = model.CreatedAgent,
                            CreatedBy         = model.CreatedBy,
                            CreatedUtc        = model.CreatedUtc,
                            DeletedAgent      = model.DeletedAgent,
                            DeletedBy         = model.DeletedBy,
                            DeletedUtc        = model.DeletedUtc,
                            LastModifiedAgent = model.LastModifiedAgent,
                            LastModifiedBy    = model.LastModifiedBy,
                            LastModifiedUtc   = model.LastModifiedUtc,
                            UId = model.UId,

                            SalesReceiptDetails = new List <SalesReceiptDetailModel>
                            {
                                item
                            }
                        };

                        do
                        {
                            model.Code = CodeGenerator.Generate();
                        }while (DbSet.Any(d => d.Code.Equals(model.Code)));

                        SalesReceiptNumberGenerator(model, index);
                        salesReceiptLogic.Create(model);
                        index++;
                    }
                    result = await DbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(result);
        }