Example #1
0
        public async Task <EmailSentResult> ContactSendEmailToAdmin(ContactSendMessageViewModel contactSendMessageViewModel)
        {
            try
            {
                string emailTitle    = $"City Glass - Contact Us!";
                string emailSubject  = emailTitle;
                string emailTemplate = EmailTemplateHelper.GetContactSendMessageEmailTemplate(emailTitle, contactSendMessageViewModel: contactSendMessageViewModel);

                string emailAddressDisplayName = _cityGlassContactUsConfig.EmailAddressDisplayName;
                string emailAddress            = _cityGlassContactUsConfig.EmailAddress;

                if (contactSendMessageViewModel.MessageCategoryValue == MessageCategoryValueEnum.CommercialGlassWindowsAndDoors.ToString())
                {
                    emailAddress = _cityGlassContactUsConfig.CommercialGlassWindowsAndDoors;
                }
                else if (contactSendMessageViewModel.MessageCategoryValue == MessageCategoryValueEnum.LargeScaleGlassAndMirrorBids.ToString())
                {
                    emailAddress = _cityGlassContactUsConfig.LargeScaleGlassAndMirrorBids;
                }
                else if (contactSendMessageViewModel.MessageCategoryValue == MessageCategoryValueEnum.MirrorShowerGlassInstallation.ToString())
                {
                    emailAddress = _cityGlassContactUsConfig.MirrorShowerGlassInstallation;
                }
                else if (contactSendMessageViewModel.MessageCategoryValue == MessageCategoryValueEnum.ResidentialGlassWindowsAndDoors.ToString())
                {
                    emailAddress = _cityGlassContactUsConfig.ResidentialGlassWindowsAndDoors;
                }
                else if (contactSendMessageViewModel.MessageCategoryValue == MessageCategoryValueEnum.TheOnlineEstimates.ToString())
                {
                    emailAddress = _cityGlassContactUsConfig.TheOnlineEstimates;
                }

                EmailMessage emailMessage = new EmailMessage();
                emailMessage.ReceiverName  = emailAddressDisplayName;
                emailMessage.ReceiverEmail = emailAddress;
                emailMessage.Subject       = emailSubject;
                emailMessage.IsHtml        = true;
                emailMessage.Body          = emailTemplate;

                var emailSentResult = await SendEmailMessage(emailMessage, "contactUsUser");

                if (!string.IsNullOrEmpty(_cityGlassEmailConfig.TestEmailAddress))
                {
                    string[] testEmailAddressList = _cityGlassEmailConfig.TestEmailAddress.Split(",");
                    foreach (var testEmailAddress in testEmailAddressList)
                    {
                        string[]     testEmailAddressReceiverEmailAndNameList = testEmailAddress.Split("_");
                        EmailMessage testEmailMessage = new EmailMessage();
                        testEmailMessage.ReceiverName  = testEmailAddressReceiverEmailAndNameList[0].ToString();
                        testEmailMessage.ReceiverEmail = testEmailAddressReceiverEmailAndNameList[1].ToString();
                        testEmailMessage.Subject       = emailSubject;
                        testEmailMessage.IsHtml        = true;
                        testEmailMessage.Body          = emailTemplate;

                        var testEmailSentResult = await SendEmailMessage(testEmailMessage, "contactUsUser");
                    }
                }

                return(emailSentResult);
            }
            catch (Exception ex)
            {
                return(new EmailSentResult {
                    Success = false, Ex = ex
                });
            }
        }