Пример #1
0
        public async Task <AccountUpdateResult> UpdateAsync(AccountUpdateArgs args)
        {
            AccountUpdateResult logicResult = new AccountUpdateResult();

            try
            {
                Account account         = args.Account.ToEntity();
                Account existingAccount = await _context.Set <Account>().Where(x => x.AccountId == account.AccountId)
                                          .FirstAsync()
                                          .ConfigureAwait(false);

                account.Id                  = existingAccount.Id;
                account.AccountId           = existingAccount.AccountId;
                account.MetaCreatedTimeCode = existingAccount.MetaCreatedTimeCode;
                account.MetaIsDeleted       = existingAccount.MetaIsDeleted;
                account.MetaRowVersion      = existingAccount.MetaRowVersion;
                EntitiesExpress.CopyProperties(account, existingAccount);
                existingAccount.MetaModifiedTimeCode = DateTime.UtcNow.ToSuperEpochUtc();
                _ = await _context.SaveChangesAsync()
                    .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                logicResult.Exception = ex;
            }
            return(logicResult);
        }
        public async Task <AccountModifyResult> Handle(AccountModifyCommand command, CancellationToken cancellationToken)
        {
            AccountModifyResult logicResult = new AccountModifyResult();

            try
            {
                AccountFindArgs accountFindArgs = new AccountFindArgs
                {
                    AccountId = command.Args.AccountId
                };
                AccountFindResult accountFindResult = await _accountRepository.FindAsync(accountFindArgs)
                                                      .ConfigureAwait(false);

                accountFindResult.EnsureSuccess();

                Account account = Account.Load(accountFindResult.Result);
                account.Modify(command.Args);
                AccountUpdateArgs accountUpdateArgs = new AccountUpdateArgs
                {
                    Account = account
                };
                AccountUpdateResult accountUpdateResult = await _accountRepository.UpdateAsync(accountUpdateArgs)
                                                          .ConfigureAwait(false);

                accountUpdateResult.EnsureSuccess();
                logicResult.Result = accountUpdateResult.Result;
            }
            catch (Exception ex)
            {
                logicResult.Exception = ex;
            }
            return(logicResult);
        }