Пример #1
0
        public int Add(OperationDto item)
        {
            using (SpendingsEntities context = new SpendingsEntities())
            {
                Operation toAdd = Mapper.Map <OperationDto, Operation>(item);

                context.Operations.Add(toAdd);
                context.SaveChanges();

                return(toAdd.Id);
            }
        }
Пример #2
0
        public void Update(OperationDto item)
        {
            Operation operation = Mapper.Map <OperationDto, Operation>(item);

            using (SpendingsEntities context = new SpendingsEntities())
            {
                context.Operations.Attach(operation);
                context.Entry(operation).State = EntityState.Modified;

                context.SaveChanges();
            }
        }
Пример #3
0
        public int Add(AccountDto item)
        {
            using (SpendingsEntities context = new SpendingsEntities())
            {
                //Account toAdd = new Account();
                //toAdd.Name = item.Name;
                //toAdd.Currency = item.Currency;

                Account toAdd = Mapper.Map <AccountDto, Account>(item);

                context.Accounts.Add(toAdd);
                context.SaveChanges();

                return(toAdd.Id);
            }
        }
Пример #4
0
        public bool Delete(int id)
        {
            using (SpendingsEntities context = new SpendingsEntities())
            {
                Operation toDelete = context.Operations.FirstOrDefault(d => d.Id == id);

                if (toDelete == null)
                {
                    return(false);
                }

                context.Operations.Remove(toDelete);
                context.SaveChanges();

                return(true);
            }
        }
        public int Add(OperationTypeDto item)
        {
            using (SpendingsEntities context = new SpendingsEntities())
            {
                //OperationType toAdd = new OperationType();
                //toAdd.Name = item.Name;
                //toAdd.Description = item.Description;
                //toAdd.IsCredit = item.IsCredit;

                OperationType toAdd = Mapper.Map <OperationType>(item);

                context.OperationTypes.Add(toAdd);
                context.SaveChanges();

                return(toAdd.Id);
            }
        }
        public void Update(OperationTypeDto item)
        {
            using (SpendingsEntities context = new SpendingsEntities())
            {
                OperationType OT = Mapper.Map <OperationTypeDto, OperationType>(item);
                context.OperationTypes.Attach(OT);
                context.Entry(OT).State = System.Data.Entity.EntityState.Modified;

                //OperationType fromDb = context.OperationTypes.FirstOrDefault(d => d.Id == item.Id);

                //if (fromDb == null)
                //{
                //    return;
                //}

                //fromDb.Name = item.Name;
                //fromDb.Description = item.Description;
                //fromDb.IsCredit = item.IsCredit;

                context.SaveChanges();
            }
        }
Пример #7
0
        public void Update(AccountDto item)
        {
            //map to Account
            Account account = Mapper.Map <AccountDto, Account>(item);

            using (SpendingsEntities context = new SpendingsEntities())
            {
                //find in database and attach to the account object
                //account.Id select top 1 from Accounts where Id == account.Id
                context.Accounts.Attach(account);

                //mark entity as modified
                context.Entry(account).State = EntityState.Modified;

                //mark certain properties as modified
                //context.Entry(account).Property(d => d.Currency).IsModified = true;
                //context.Entry(account).Property(d => d.Name).IsModified = true;

                //save modifications
                context.SaveChanges();
            }
        }