예제 #1
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();
            }
        }
        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();
            }
        }
예제 #3
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();
            }
        }