Ejemplo n.º 1
0
        public bool Delete(List <int> ids)
        {
            //try
            //{
            using (FinanceEntities context = factory.CreateContext())
            {
                //context.Cashflows.Delete(e=>ids.Contains(e.CashflowId));

                foreach (var id in ids)
                {
                    var ef = new Cashflow()
                    {
                        CashflowId = id
                    };
                    context.Entry(ef).State = EntityState.Deleted;
                }

                // deletes are cascaded to CashflowBankAccount
                context.SaveChanges();
            }
            //}
            //catch (DbEntityValidationException e)
            //{
            //    CommonRepository.HandleDbEntityValidationException(e);
            //}
            return(true);
        }
Ejemplo n.º 2
0
        public bool Delete(Core.Entities.BankAccount entity)
        {
            var ef = mapper.Map <BankAccount>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Deleted;
                context.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool Update(Core.Entities.BankAccount entity)
        {
            var ef = mapper.Map <BankAccount>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Modified;
                context.SaveChanges();
            }
            //read back columns which may have changed
            entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;
            return(true);
        }
Ejemplo n.º 4
0
        public bool Delete(Core.Entities.BalanceDate entity)
        {
            var ef = mapper.Map <BalanceDate>(entity);

            //need to delete children to prevent EF FK error
            ef.BalanceDateBankAccounts.Clear();
            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Deleted;
                // deletes are cascaded to BalanceBankAccount
                context.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 5
0
 public bool Delete(List <int> ids)
 {
     using (FinanceEntities context = factory.CreateContext())
     {
         foreach (var id in ids)
         {
             var ef = new BankAccount()
             {
                 BankAccountId = id
             };
             context.Entry(ef).State = EntityState.Deleted;
         }
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 6
0
        public int Add(Core.Entities.BankAccount entity)
        {
            int id = 0;
            var ef = mapper.Map <BankAccount>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Added;
                context.SaveChanges();
            }
            //read back columns which may have changed
            entity.BankAccountId         = ef.BankAccountId;
            entity.RecordCreatedDateTime = ef.RecordCreatedDateTime;
            entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;
            id = ef.BankAccountId;
            return(id);
        }
Ejemplo n.º 7
0
        public int Add(Core.Entities.Cashflow entity)
        {
            int id = 0;
            //try
            //{
            var ef = mapper.Map <Cashflow>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Added;
                context.SaveChanges();
            }
            //read back columns which may have changed
            entity.CashflowId            = ef.CashflowId;
            entity.RecordCreatedDateTime = ef.RecordCreatedDateTime;
            entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;

            int i = 0;

            foreach (var cba in ef.CashflowBankAccounts)
            {
                if (entity.CashflowBankAccounts.Count <= i)
                {
                    break;
                }

                var e = entity.CashflowBankAccounts[i];

                e.CashflowBankAccountId = cba.CashflowBankAccountId;
                e.RecordCreatedDateTime = cba.RecordCreatedDateTime;

                i++;
            }

            id = ef.CashflowId;
            //}
            //catch (DbEntityValidationException e)
            //{
            //    CommonRepository.HandleDbEntityValidationException(e);
            //}
            return(id);
        }
Ejemplo n.º 8
0
        public bool Delete(Core.Entities.Cashflow entity)
        {
            //try
            //{
            var ef = mapper.Map <Cashflow>(entity);

            ef.CashflowBankAccounts.Clear();
            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Deleted;
                // deletes are cascaded to CashflowBankAccount
                context.SaveChanges();
            }
            //}
            //catch (DbEntityValidationException e)
            //{
            //    CommonRepository.HandleDbEntityValidationException(e);
            //}
            return(true);
        }
Ejemplo n.º 9
0
        public int Add(Core.Entities.BalanceDate entity)
        {
            int id = 0;
            var ef = mapper.Map <BalanceDate>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                context.Entry(ef).State = EntityState.Added;
                context.SaveChanges();
            }
            //read back columns which may have changed
            entity.BalanceDateId         = ef.BalanceDateId;
            entity.RecordCreatedDateTime = ef.RecordCreatedDateTime;
            //entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;

            int i = 0;

            foreach (var cba in ef.BalanceDateBankAccounts)
            {
                if (entity.BalanceDateBankAccounts.Count <= i)
                {
                    break;
                }

                var e = entity.BalanceDateBankAccounts[i];

                e.BalanceDateBankAccountId = cba.BalanceDateBankAccountId;
                e.RecordCreatedDateTime    = cba.RecordCreatedDateTime;

                i++;
            }


            id = ef.BalanceDateId;
            return(id);
        }
Ejemplo n.º 10
0
        public bool Update(Core.Entities.Cashflow entity)
        {
            //throw new Exception("testing");

            //try
            //{
            var ef = mapper.Map <Cashflow>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                // read in children
                var cbas = from b in context.CashflowBankAccounts
                           where b.CashflowId == ef.CashflowId
                           select b;

                foreach (var cba in cbas)
                {
                    if (ef.CashflowBankAccounts.Count(a => a.CashflowBankAccountId == cba.CashflowBankAccountId) == 0)
                    {
                        context.Entry(cba).State = EntityState.Deleted;
                    }
                    else
                    {
                        context.Entry(cba).State = EntityState.Detached;
                    }
                }

                foreach (var cba in ef.CashflowBankAccounts)
                {
                    if (cba.CashflowBankAccountId > 0)
                    {
                        context.Entry(cba).State = EntityState.Modified;
                    }
                    else
                    {
                        context.Entry(cba).State = EntityState.Added;
                    }
                }

                context.Entry(ef).State = EntityState.Modified;

                var s = ShowEntityStates(context);

                context.SaveChanges();
            }
            //read back data which may have changed
            entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;

            int i = 0;

            foreach (var cba in ef.CashflowBankAccounts)
            {
                if (entity.CashflowBankAccounts.Count <= i)
                {
                    break;
                }

                var e = entity.CashflowBankAccounts[i];

                if (e.CashflowBankAccountId == 0)
                {
                    e.CashflowBankAccountId = cba.CashflowBankAccountId;
                    e.RecordCreatedDateTime = cba.RecordCreatedDateTime;
                }
                i++;
            }

            //}
            //catch (DbEntityValidationException e)
            //{
            //    CommonRepository.HandleDbEntityValidationException(e);
            //}
            return(true);
        }
Ejemplo n.º 11
0
        public bool Update(Core.Entities.BalanceDate entity)
        {
            var ef = mapper.Map <BalanceDate>(entity);

            using (FinanceEntities context = factory.CreateContext())
            {
                // read in children
                var cbas = from b in context.BalanceDateBankAccounts
                           where b.BalanceDateId == ef.BalanceDateId
                           select b;

                foreach (var cba in cbas)
                {
                    if (ef.BalanceDateBankAccounts.Count(a => a.BalanceDateBankAccountId == cba.BalanceDateBankAccountId) == 0)
                    {
                        context.Entry(cba).State = EntityState.Deleted;
                    }
                    else
                    {
                        context.Entry(cba).State = EntityState.Detached;
                    }
                }

                foreach (var cba in ef.BalanceDateBankAccounts)
                {
                    if (cba.BalanceDateBankAccountId > 0)
                    {
                        context.Entry(cba).State = EntityState.Modified;
                    }
                    else
                    {
                        context.Entry(cba).State = EntityState.Added;
                    }
                }



                context.Entry(ef).State = EntityState.Modified;

                var s = ShowEntityStates(context);

                context.SaveChanges();
            }
            //read back data which may have changed
            //entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime;

            int i = 0;

            foreach (var cba in ef.BalanceDateBankAccounts)
            {
                if (entity.BalanceDateBankAccounts.Count <= i)
                {
                    break;
                }

                var e = entity.BalanceDateBankAccounts[i];

                e.BalanceDateBankAccountId = cba.BalanceDateBankAccountId;
                e.RecordCreatedDateTime    = cba.RecordCreatedDateTime;

                i++;
            }

            return(true);
        }