示例#1
0
        private void UpdateAccount(AccountDomainModel item)
        {
            using (var ctx = new BankAccountDbContext())
            {
                var entity = ctx.AccountSet.SingleOrDefault(b => b.AggregateId == item.Id);
                if (entity == null)
                {
                    throw new AggregateNotFoundException("account");
                }

                var customerEntityId =
                    ctx.CustomerSet.SingleOrDefault(c => c.AggregateId == item.CustomerId);
                if (customerEntityId == null)
                {
                    throw new AggregateNotFoundException("Bank account");
                }

                entity.Version             = item.Version;
                entity.Currency            = item.Currency;
                entity.CustomerAggregateId = item.CustomerId;
                entity.AccountState        = item.State;

                ctx.Entry(entity).State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }
        public void Update(Guid aggregateId, State customerState, int version)
        {
            using (var ctx = new BankAccountDbContext())
            {
                var entity = ctx.CustomerSet.SingleOrDefault(cust => cust.AggregateId == aggregateId);
                if (entity == null)
                {
                    throw new ArgumentNullException($"Customer entity not found");
                }

                entity.CustomerState = customerState;
                entity.Version       = version;

                ctx.Entry(entity).State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }