예제 #1
0
        internal static string Delete(int invId, string deleteReason)
        {
            string isSaved = "false";

            if (invId == 0)
            {
                return(isSaved);
            }

            AccountingEntities db = new AccountingEntities();

            InvoiceAP invDb = new InvoiceAP();

            invDb = db.InvoiceAPs
                    .Where(x => x.InvoiceId == invId).FirstOrDefault();

            int?transID = null;

            if (invDb.TransId != null)
            {
                transID = invDb.TransId.Value;
            }

            if (invDb.InvStatusId == 1 || invDb.InvStatusId == 2)
            {
                invDb.IsDeleted    = true;
                invDb.DeleteReason = deleteReason;
                invDb.DeletedBy    = EasyFreight.DAL.AdminHelper.GetCurrentUserId();
                invDb.TransId      = null;

                // invoice total
                var invTotal = db.InvoiceTotalAPs.Where(x => x.InvoiceId == invId).FirstOrDefault();

                try
                {
                    db.SaveChanges();

                    db.InvoiceTotalAPs.Remove(invTotal);

                    if (transID.HasValue)
                    {
                        AccountingHelper.DeleteTransaction(transID.Value);
                    }


                    isSaved = "true";
                }
                catch
                {
                    isSaved = "false";
                }
            }

            return(isSaved);
        }
예제 #2
0
        internal static string Delete(int invId, string deleteReason)
        {
            string isSaved = "false";

            if (invId == 0)
            {
                return(isSaved);
            }

            AccountingEntities db = new AccountingEntities();

            Invoice invDb = new Invoice();

            invDb = db.Invoices
                    .Where(x => x.InvoiceId == invId).FirstOrDefault();

            int?transID = null;

            if (invDb.TransId != null)
            {
                transID = invDb.TransId.Value;
            }

            if (invDb.InvStatusId == 1 || invDb.InvStatusId == 2)
            {
                invDb.IsDeleted    = true;
                invDb.DeleteReason = deleteReason;
                invDb.DeletedBy    = EasyFreight.DAL.AdminHelper.GetCurrentUserId();
                invDb.TransId      = null;

                // invoice total
                var invTotal = db.InvoiceTotals.Where(x => x.InvoiceId == invId).FirstOrDefault();

                try
                {
                    db.SaveChanges();

                    db.InvoiceTotals.Remove(invTotal);

                    if (transID.HasValue)
                    {
                        AccountingHelper.DeleteTransaction(transID.Value);
                    }

                    #region Update Operation Status...
                    try
                    {
                        var provInvs = db.Invoices
                                       .Where(x => x.OperationId == invDb.OperationId && x.IsDeleted == null && x.InvoiceId != invDb.InvoiceId).ToList();
                        if (provInvs.Count == 0)
                        {
                            OperationsEntities opdb = new OperationsEntities();
                            var operation           = opdb.Operations.Where(z => z.OperationId == invDb.OperationId).FirstOrDefault();
                            operation.StatusId = 3;
                            opdb.SaveChanges();
                        }
                    }
                    catch { }
                    #endregion

                    isSaved = "true";
                }
                catch
                {
                    isSaved = "false";
                }
            }

            return(isSaved);
        }