示例#1
0
 public void save(ChartOfAccounts ChartOfAccounts, string userId, bool isNew)
 {
     try
     {
         using (var context = new SmsMisDB())
         {
             var mainentry = context.Entry(ChartOfAccounts);
             if (mainentry != null)
             {
                 ChartOfAccounts.AddDateTime = DateTime.Now;
                 ChartOfAccounts.AddByUserId = userId;
                 if (isNew)
                 {
                     //ChartOfAccounts.VoucherCode = Functions.getNextPk("VoucherType", ChartOfAccounts.VoucherCode, ChartOfAccounts.CompanyCode);
                     mainentry.State = EntityState.Added;
                     context.ChartOfAccounts.Add(ChartOfAccounts);
                 }
                 else
                 {
                     mainentry.State = EntityState.Modified;
                 }
                 if (ChartOfAccounts.COABranch != null && ChartOfAccounts.COABranch.Count > 0)
                 {
                     ChartOfAccounts.COABranch.ToList <COABranch>().ForEach(entry => context.Entry(entry).State = EntityState.Added);
                 }
                 context.COABranch.ToList().Where(i => i.CompanyCode == ChartOfAccounts.CompanyCode && i.AccountCode == ChartOfAccounts.AccountCode).ToList <COABranch>().ForEach(entry => context.Entry(entry).State = EntityState.Deleted);
                 context.SaveChanges();
                 Bank bnk = new hdlBank().SelectBankByAccountCode(ChartOfAccounts.AccountCode, ChartOfAccounts.CompanyCode);
                 if (bnk != null && ChartOfAccounts.AccountType != "B")
                 {
                     new hdlBank().delete(bnk);
                 }
             }
         }
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException ex)
     {
         //throw ex;
     }
     catch (Exception ex)
     {
         // throw ex;
     }
 }
示例#2
0
        public void delete(ChartOfAccounts ChartOfAccounts)
        {
            using (var context = new SmsMisDB())
            {
                //var context = new SmsMisDB();
                Bank bnk = new hdlBank().SelectBankByAccountCode(ChartOfAccounts.AccountCode, ChartOfAccounts.CompanyCode);

                context.ChartOfAccounts.Attach(ChartOfAccounts);
                var entry = context.Entry(ChartOfAccounts);
                if (entry != null)
                {
                    entry.State = EntityState.Deleted;
                    context.COABranch.ToList().Where(i => i.CompanyCode == ChartOfAccounts.CompanyCode && i.AccountCode == ChartOfAccounts.AccountCode).ToList <COABranch>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted);
                    context.SaveChanges();
                    if (bnk != null)
                    {
                        new hdlBank().delete(bnk);
                    }
                }
                //var entry = context.Entry(ChartOfAccounts);
                //context.ChartOfAccounts.Remove(ChartOfAccounts);
            }
        }