Esempio n. 1
0
        public async Task <DeleteUserResponse> Handle(DeleteUserRequest request, CancellationToken cancellationToken)
        {
            bool success = false;

            if (request.UserID > 0)
            {
                var result = _repository.GetUserByID(request.UserID);
                if (result != null && result.PostalCode == request.Postcode)
                {
                    success = _authService.DeleteUser(result.FirebaseUID).Result;

                    if (success)
                    {
                        success = await _repository.DeleteUserAsync(request.UserID, cancellationToken);

                        bool deletedMarketingContact = await _communicationService.DeleteMarketingContactAsync(new DeleteMarketingContactRequest()
                        {
                            EmailAddress = result.UserPersonalDetails.EmailAddress
                        }, cancellationToken);

                        if (!deletedMarketingContact)
                        {
                            throw new Exception("Unable to delete email address from marketing list");
                        }
                    }
                }
            }

            return(new DeleteUserResponse()
            {
                Success = success
            });
        }