Exemple #1
0
        public async Task <int> DeleteAsync(int id)
        {
            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    SalesInvoiceModel model = await salesInvoiceLogic.ReadByIdAsync(id);

                    if (model != null)
                    {
                        SalesInvoiceModel salesInvoiceModel = new SalesInvoiceModel();
                        salesInvoiceModel = model;
                        await salesInvoiceLogic.DeleteAsync(id);
                    }

                    if (model.SalesInvoiceCategory == "DYEINGPRINTING")
                    {
                        foreach (var detail in model.SalesInvoiceDetails)
                        {
                            var ItemIds = detail.SalesInvoiceItems.Select(s => s.ProductId).ToList();
                            UpdateFalseToShippingOut(detail.ShippingOutId, ItemIds);
                        }
                    }


                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(await DbContext.SaveChangesAsync());
        }
        public async Task <int> DeleteAsync(int id)
        {
            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    SalesInvoiceModel model = await salesInvoiceLogic.ReadByIdAsync(id);

                    if (model != null)
                    {
                        SalesInvoiceModel salesInvoiceModel = new SalesInvoiceModel();
                        salesInvoiceModel = model;
                        await salesInvoiceLogic.DeleteAsync(id);
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(await DbContext.SaveChangesAsync());
        }