Esempio n. 1
0
        public EmailResponseDto <EmailTemplateDto> AddEmailTemplate(EmailTemplateDto templateInput)
        {
            var response = new EmailResponseDto <EmailTemplateDto>();

            if (!string.IsNullOrEmpty(templateInput.EmailPoolName))
            {
                if (string.IsNullOrEmpty(templateInput.EmailPoolID))
                {
                    var emailPool = _emailPoolRepository.GetEmailPoolByName(templateInput.EmailPoolName)?.Result;
                    if (emailPool != null)
                    {
                        templateInput.EmailPoolID = emailPool.ID;
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = "Invalid Email pool.";
                        response.Result  = templateInput;
                        return(response);
                    }
                }
                else
                {
                    var emailPool = _emailPoolRepository.CheckIfEmailPoolIDNameValid(templateInput.EmailPoolID, templateInput.EmailPoolName);
                    if (!emailPool.Status)
                    {
                        response.Status  = false;
                        response.Message = "Email Pool ID and Name do not match.";
                        response.Result  = templateInput;
                        return(response);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(templateInput.EmailPoolID))
            {
                var emailPool = _emailPoolRepository.CheckIfEmailPoolIDIsValid(templateInput.EmailPoolID);
                if (!emailPool.Status)
                {
                    response.Status  = false;
                    response.Message = "Invalid Email Pool ID.";
                    response.Result  = templateInput;
                    return(response);
                }
            }
            else
            {
                response.Status  = false;
                response.Message = "Email pool cannot be blank.";
                response.Result  = templateInput;
                return(response);
            }
            var mappedInput    = _mapper.Map <EmailTemplateTable>(templateInput);
            var mappedResponse = _emailTemplateRepository.AddEmailTemplate(mappedInput);

            response = _mapper.Map <EmailResponseDto <EmailTemplateDto> >(mappedResponse);
            return(response);
        }
        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);
        }