public EmailResponseDto <EmailChannelDto> AddEmailChannel(EmailChannelDto channelInput)
        {
            var response = new EmailResponseDto <EmailChannelDto>();

            if (!string.IsNullOrEmpty(channelInput.EmailPoolName))
            {
                if (string.IsNullOrEmpty(channelInput.EmailPoolID))
                {
                    var emailPool = _emailPoolRepository.GetEmailPoolByName(channelInput.EmailPoolName)?.Result;
                    if (emailPool != null)
                    {
                        channelInput.EmailPoolID = emailPool.ID;
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = "Invalid Email pool.";
                        response.Result  = channelInput;
                        return(response);
                    }
                }
                else
                {
                    var emailPool = _emailPoolRepository.CheckIfEmailPoolIDNameValid(channelInput.EmailPoolID, channelInput.EmailPoolName);
                    if (!emailPool.Status)
                    {
                        response.Status  = false;
                        response.Message = "Email Pool ID and Pool Name do not match.";
                        response.Result  = channelInput;
                        return(response);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(channelInput.EmailPoolID))
            {
                var emailPool = _emailPoolRepository.CheckIfEmailPoolIDIsValid(channelInput.EmailPoolID);
                if (!emailPool.Status)
                {
                    response.Status  = false;
                    response.Message = "Invalid Email Pool ID.";
                    response.Result  = channelInput;
                    return(response);
                }
            }
            else
            {
                response.Status  = false;
                response.Message = "Email pool cannot be blank.";
                response.Result  = channelInput;
                return(response);
            }
            if (!string.IsNullOrEmpty(channelInput.EmailProviderName))
            {
                if (string.IsNullOrEmpty(channelInput.EmailProviderID))
                {
                    var emailProvider = _emailProviderRepository.GetEmailProviderByName(channelInput.EmailProviderName)?.Result;
                    if (emailProvider != null)
                    {
                        channelInput.EmailProviderID = emailProvider.ID;
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = "Invalid Email provider.";
                        response.Result  = channelInput;
                        return(response);
                    }
                }
                else
                {
                    var emailProvider = _emailProviderRepository.CheckIfEmailProviderIDNameValid(channelInput.EmailProviderID, channelInput.EmailProviderName);
                    if (!emailProvider.Status)
                    {
                        response.Status  = false;
                        response.Message = "Email Provider ID and Provider Name do not match.";
                        response.Result  = channelInput;
                        return(response);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(channelInput.EmailProviderID))
            {
                var emailProvider = _emailProviderRepository.CheckIfEmailProviderIDIsValid(channelInput.EmailProviderID);
                if (!emailProvider.Status)
                {
                    response.Status  = false;
                    response.Message = "Invalid Email Provider ID.";
                    response.Result  = channelInput;
                    return(response);
                }
            }
            else
            {
                channelInput.EmailProviderID = _emailProviderRepository.GetEmailProviderByName(defaultEmailProvider)?.Result?.ID;
            }

            var mappedEmailInput = _mapper.Map <EmailChannelTable>(channelInput);
            var mappedResponse   = _emailChannelRepository.AddEmailChannel(mappedEmailInput);

            response = _mapper.Map <EmailResponseDto <EmailChannelDto> >(mappedResponse);
            return(response);
        }
        public EmailResponseDto <EmailHistoryDto> AddEmailHistory(EmailHistoryDto historyInput)
        {
            _logger.LogInformation("AddEmailHistory interactor method.");
            var response = new EmailResponseDto <EmailHistoryDto>();

            try
            {
                if (!string.IsNullOrEmpty(historyInput.ProviderName))
                {
                    _logger.LogDebug($"Providername: {historyInput.ProviderName}");
                    if (string.IsNullOrEmpty(historyInput.EmailProviderID))
                    {
                        historyInput.EmailProviderID = _emailProviderRepository.GetEmailProviderByName(historyInput.ProviderName)?.Result?.ID;
                        _logger.LogDebug($"EmailProviderID: {historyInput.EmailProviderID}");
                    }
                    else
                    {
                        var emailProvider = _emailProviderRepository.CheckIfEmailProviderIDNameValid(historyInput.EmailProviderID, historyInput.ProviderName);
                        if (!emailProvider.Status)
                        {
                            response.Status  = false;
                            response.Message = "Email Provider ID and Provider Name do not match.";
                            response.Result  = historyInput;
                            return(response);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(historyInput.EmailProviderID))
                {
                    var emailProvider = _emailProviderRepository.CheckIfEmailProviderIDIsValid(historyInput.EmailProviderID);
                    if (!emailProvider.Status)
                    {
                        response.Status  = false;
                        response.Message = "Invalid Email Provider ID.";
                        response.Result  = historyInput;
                        return(response);
                    }
                }
                else
                {
                    response.Status  = false;
                    response.Message = "Email Provider ID or Name cannot be blank.";
                    response.Result  = historyInput;
                    _logger.LogError($"{response.Message}");
                    return(response);
                }
                if (!string.IsNullOrEmpty(historyInput.ChannelKey))
                {
                    _logger.LogDebug($"ChannelKey: {historyInput.ChannelKey}");
                    if (string.IsNullOrEmpty(historyInput.EmailChannelID))
                    {
                        historyInput.EmailChannelID = _emailChannelRepository.GetEmailChannelByKey(historyInput.ChannelKey)?.Result?.ID;
                        _logger.LogDebug($"EmailChannelID: {historyInput.EmailChannelID}");
                    }
                    else
                    {
                        var emailChannel = _emailChannelRepository.CheckIfEmailChannelIDKeyValid(historyInput.EmailChannelID, historyInput.ChannelKey);
                        if (!emailChannel.Status)
                        {
                            _logger.LogError($"{emailChannel.Message}");
                            response.Status  = false;
                            response.Message = emailChannel.Message;
                            response.Result  = historyInput;
                            return(response);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(historyInput.EmailChannelID))
                {
                    var emailChannel = _emailChannelRepository.CheckIfEmailChannelIDIsValid(historyInput.EmailChannelID);
                    if (!emailChannel.Status)
                    {
                        _logger.LogError($"{emailChannel.Message}");
                        response.Status  = false;
                        response.Message = emailChannel.Message;
                        response.Result  = historyInput;
                        return(response);
                    }
                }
                else
                {
                    response.Status  = false;
                    response.Message = "Email Channel ID or Key cannot be blank.";
                    response.Result  = historyInput;
                    _logger.LogError($"{response.Message}");
                    return(response);
                }
                var mappedEmailInput = _mapper.Map <EmailHistoryTable>(historyInput);
                var mappedResponse   = _emailHistoryRepository.AddEmailHistory(mappedEmailInput);
                response = _mapper.Map <EmailResponseDto <EmailHistoryDto> >(mappedResponse);
                _logger.LogDebug($"Status: {response.Status}, Message: {response.Message}");
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error occurred while adding email history:" + ex.Message);
                response.Message = "Error occurred while adding email history: " + ex.Message;
                response.Status  = false;
                return(response);
            }
        }