Exemple #1
0
        public EmailResponseDto <EmailChannelDto> AddEmailChannel(EmailChannelDto channelInput)
        {
            _logger.LogInformation("AddEmailChannel interactor method.");
            EmailResponseDto <EmailChannelDto> channelResponse = new EmailResponseDto <EmailChannelDto>();

            try
            {
                _logger.LogInformation("Trying to add EmailChannel.");
                channelResponse = _emailChannelInteractor.AddEmailChannel(channelInput);
                _logger.LogDebug("" + channelResponse.Message);
                return(channelResponse);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error occurred in Email Interactor while adding email channel: ", ex.Message);
                channelResponse.Message = "Error occurred while adding email channel: " + ex.Message;
                channelResponse.Status  = false;
                return(channelResponse);
            }
        }
 public ActionResult UpdateEmailChannel(EmailChannelDto channelInput)
 {
     _logger.LogInformation("UpdateEmailChannel action method.");
     _logger.LogDebug($"EmailPoolName: {channelInput.EmailPoolName}, EmailProviderName: {channelInput.EmailProviderName}");
     try
     {
         var channelResponse = _emailInteractor.UpdateEmailChannel(channelInput);
         if (channelResponse.Status)
         {
             _logger.LogDebug("Status: " + channelResponse.Status + ", " + channelResponse.Message);
             return(Ok(channelResponse));
         }
         else
         {
             _logger.LogError("Status: " + channelResponse.Status + ", " + channelResponse.Message);
             return(StatusCode((int)HttpStatusCode.PreconditionFailed, channelResponse));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("Internal server error: Error occurred while updating email channel: " + ex.Message);
         return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
     }
 }
        public ActionResult AddEmailChannel(EmailChannelDto channelInput)
        {
            _logger.LogInformation("AddEmailChannel action method.");
            _logger.LogDebug($"EmailPoolName: {channelInput.EmailPoolName}, EmailProviderName: {channelInput.EmailProviderName}");
            EmailResponseDto <EmailChannelDto> channelResponse = new EmailResponseDto <EmailChannelDto>();

            try
            {
                if (!string.IsNullOrWhiteSpace(channelInput.Key))
                {
                    channelResponse = _emailInteractor.AddEmailChannel(channelInput);
                    if (channelResponse.Status)
                    {
                        _logger.LogDebug("Status: " + channelResponse.Status + ", " + channelResponse.Message);
                        return(Ok(channelResponse));
                    }
                    else
                    {
                        _logger.LogError("Status: " + channelResponse.Status + ", " + channelResponse.Message);
                        return(StatusCode((int)HttpStatusCode.PreconditionFailed, channelResponse));
                    }
                }
                else
                {
                    channelResponse.Status  = false;
                    channelResponse.Message = "Channel Key cannot be empty or whitespace.";
                    _logger.LogError("Status: " + channelResponse.Status + ", " + channelResponse.Message);
                    return(StatusCode((int)HttpStatusCode.PreconditionFailed, channelResponse));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Internal server error: Error occurred while adding email channel: " + ex.Message);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
        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);
        }