Ejemplo n.º 1
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.RemoveCustomerAccount(Guid)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <returns></returns>
        public async Task RemoveCustomerAccount(Guid customerId)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

            var customer = await Repository.GetByKeyAsync <Customer>(customerId);

            if (customer == null)
            {
                throw new ArgumentOutOfRangeException(nameof(customerId));
            }

            try
            {
                var    accountId = customer.Account.UserId;
                string userName  = customer.Account.UserName;

                customer.RemoveAccount();
                await AuthClient.DisableAccount(accountId);

                await Repository.SaveChangesAsync();

                var @event = new CustomerAccountRemovedEvent(customerId, userName);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.DeleteCustomer(Guid)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <returns></returns>
        public async Task DeleteCustomer(Guid customerId)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

            var customer = await Repository.GetByKeyAsync <Customer>(customerId);

            if (customer == null)
            {
                throw new ArgumentOutOfRangeException(nameof(customerId));
            }

            try
            {
                customer.Delete();
                if (customer.HasAccount)
                {
                    await AuthClient.DisableAccount(customer.Account.UserId);

                    customer.LockAccount();
                }

                await Repository.SaveChangesAsync();

                var @event = new CustomerDeletedEvent(customerId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }