コード例 #1
0
        public int RemoveTransaction(Guid transId, DbContextOptionsBuilder <LedgerContext> context)
        {
            using (var ctx = new LedgerContext(context.Options))
            {
                var entity = ctx.Transactions.FirstOrDefault(t => t.Id == transId);
                if (entity != null)
                {
                    ctx.Entry(entity).State = EntityState.Deleted;
                }

                return(ctx.SaveChanges());
            }
        }
コード例 #2
0
        public void AddAuxAccount(AuxiliaryAccountViewModel vmAuxAccount)
        {
            Account auxAccount = this.GetAccount(vmAuxAccount.AccId);

            _ledger.Entry(auxAccount).State = System.Data.Entity.EntityState.Detached;
            auxAccount.AccId = 0;

            List <Auxiliary> auxList = new List <Auxiliary>();

            if (vmAuxAccount.Custom.HasValue && vmAuxAccount.Custom.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Custom.Value));
            }
            if (vmAuxAccount.Suppliers.HasValue && vmAuxAccount.Suppliers.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Suppliers.Value));
            }
            if (vmAuxAccount.Employee.HasValue && vmAuxAccount.Employee.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Employee.Value));
            }
            if (vmAuxAccount.Project.HasValue && vmAuxAccount.Project.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Project.Value));
            }
            if (vmAuxAccount.Sector.HasValue && vmAuxAccount.Sector.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Sector.Value));
            }
            if (vmAuxAccount.Inventory.HasValue && vmAuxAccount.Inventory.Value > 0)
            {
                auxList.Add(_auxiliary.GetAuxiliary(vmAuxAccount.Inventory.Value));
            }

            foreach (Auxiliary aux in auxList)
            {
                auxAccount.AccCode += "_" + aux.AuxCode;
                auxAccount.AccName += "_" + aux.AuxName;
            }

            _ledger.Accounts.Add(auxAccount);
            _ledger.SaveChanges();

            _cache.ClearAccountCache(_cache.GetUserCache().AccountBookID);
        }