예제 #1
0
        /// <summary>
        /// Update an existing account
        /// </summary>
        /// <param name="tenantId">a tenant</param>
        /// <param name="userId">a user</param>
        /// <param name="accountId">the id of the account to update</param>
        /// <param name="account">the account update model</param>
        /// <returns>a read-only account model</returns>
        public async Task <AccountRm> UpdateAsync(long tenantId, long userId, long accountId, AccountUm account)
        {
            var msg = "Update" + ". " +
                      string.Format("tenantId={0}, userId={1}, accountId={2}, account={3}", tenantId, userId, accountId, Serialization.Serialize(account));

            try
            {
                TenantCheck(tenantId, accountId, msg);
                Log.Debug(msg);
                // get the entity by id, we already know it exists for the client.
                var e = Repository.Get(accountId);
                // update entity
                account.UpdateEntity(e);
                await Repository.UpdateAsync(userId, e);

                // convert it to a read model
                return((AccountRm)AccountRm.From(e));
            }
            catch (EntityDoesNotExistException exception)
            {
                Log.Error(msg, exception);
                throw;
            }
            catch (Exception exception)
            {
                Log.Error(msg, exception);
                throw new ApplicationException("Failed to update the submitted " + FriendlyName);
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> Update(long id, AccountUm payload)
        {
            var vm = await _accountsService.UpdateAsync(TenantId, UserId, id, payload);

            return(Ok(vm));
        }