public async Task <int> DeleteAsync(int id)
        {
            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    SalesReceiptModel model = await salesReceiptLogic.ReadByIdAsync(id);

                    if (model != null)
                    {
                        SalesReceiptModel salesReceiptModel = new SalesReceiptModel();

                        foreach (var item in model.SalesReceiptDetails)
                        {
                            var updateToSalesInvoice = DbContext.SalesInvoices.FirstOrDefault(x => x.Id == item.SalesInvoiceId);
                            updateToSalesInvoice.TotalPaid = updateToSalesInvoice.TotalPaid - item.Nominal;
                            updateToSalesInvoice.IsPaidOff = item.IsPaidOff;
                        }

                        salesReceiptModel = model;
                        await salesReceiptLogic.DeleteAsync(id);
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(await DbContext.SaveChangesAsync());
        }
Exemplo n.º 2
0
        public async Task <int> DeleteAsync(int id)
        {
            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    SalesReceiptModel model = await salesReceiptLogic.ReadByIdAsync(id);

                    if (model != null)
                    {
                        SalesReceiptModel salesReceiptModel = new SalesReceiptModel();

                        salesReceiptModel = model;
                        await salesReceiptLogic.DeleteAsync(id);
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(await DbContext.SaveChangesAsync());
        }