コード例 #1
0
        public async Task <ContactUs> CreateContactUsAsync(int userId, ContactUsRequest request)
        {
            var user = await _uow.UserRepository.GetAsync(userId);

            if (user == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "User");
            }

            var contact = new ContactUs();

            contact.Body      = request.Body;
            contact.Subject   = request.Subject;
            contact.UserId    = userId;
            contact.User      = user;
            contact.Priority  = ContactPriorityEnum.NORMAL;
            contact.Read      = false;
            contact.CreatedAt = DateTime.UtcNow;

            await _uow.ContactUsRepository.AddAsync(contact);

            await _uow.CommitAsync();

            return(contact);
        }
コード例 #2
0
        public ActionResult AddEmailNotificationRequest(ContactUsRequest request, int type = 1)
        {
            try
            {
                //Task.Run(() => SMTPHelper.SendGridMail());
                ContactUsInfoMail newsLetterMail = new ContactUsInfoMail();
                if (type == 1)
                {
                    request.ContactUsReasonTextEn = "Email NotificationRequest";
                    request.ContactUsReasonTextAr = "طلب اشعار البريد الإلكترونى";
                    newsLetterMail.MailSubject    = $"{request.ContactUsReasonTextEn} - {request.ContactUsReasonTextAr}";
                    newsLetterMail.MailType       = $"{request.ContactUsReasonTextEn} - {request.ContactUsReasonTextAr}";
                }
                else
                {
                    //request.ContactUsReasonTextEn = "sunscription request";
                    //request.ContactUsReasonTextAr = "طلب إشتراك";
                    //newsLetterMail.MailSubject = $"{request.ContactUsReasonTextEn} - {request.ContactUsReasonTextAr}";
                    //newsLetterMail.MailType = $"{request.ContactUsReasonTextEn} - {request.ContactUsReasonTextAr}";
                }

                request.RequestDate  = System.DateTime.UtcNow;
                request.Message      = "-";
                request.Name         = "-";
                request.MobileNumber = "-";
                _contactUsRequestService.AddContactUsRequest(request);
            }
            catch (Exception ex)
            {
                var path = HostingEnvironment.MapPath("~/ErrorTxt/errorFile.txt");
                System.IO.File.WriteAllText(path, ex.Message);
            }

            return(RedirectToAction("Home", "Home"));
        }
コード例 #3
0
        public ActionResult Contact()
        {
            var request  = new ContactUsRequest();
            var response = _mediator.Send(request);

            return(View());
        }
コード例 #4
0
        public static bool InsertIntoContactUsRequest(ContactUsRequest mailinfo)
        {
            MySqlConnection connection = new MySqlConnection("Server=160.153.246.233;DataBase=theleanp_LDVRBS_DB;Uid=theleanplus;Password=P@ssw0rdFAWRY");

            string InsertQry = "INSERT INTO ContactUsRequests (Name,Email,MobileNumber,ContactUsReasonID,Message,RequestDate,ContactUsReasonTextEn,ContactUsReasonTextAr) " +
                               " Values(@Name,@Email,@MobileNumber,@ContactUsReasonID,@Message,@RequestDate,@ContactUsReasonTextEn,@ContactUsReasonTextAr)";

            MySqlCommand cmd = new MySqlCommand(InsertQry, connection);

            cmd.Parameters.AddWithValue("@Name", mailinfo.Name);
            cmd.Parameters.AddWithValue("@Email", mailinfo.Email);
            cmd.Parameters.AddWithValue("@MobileNumber", mailinfo.MobileNumber);
            cmd.Parameters.AddWithValue("@ContactUsReasonID", mailinfo.ContactUsReasonId);
            cmd.Parameters.AddWithValue("@Message", mailinfo.Message);
            cmd.Parameters.AddWithValue("@RequestDate", mailinfo.RequestDate);
            cmd.Parameters.AddWithValue("@ContactUsReasonTextEn", mailinfo.ContactUsReasonTextEn);
            cmd.Parameters.AddWithValue("@ContactUsReasonTextAr", mailinfo.ContactUsReasonTextAr);



            connection.Open();
            var rowsAdded = cmd.ExecuteNonQuery();

            connection.Close();
            if (rowsAdded > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #5
0
 public string FunctionHandler(ContactUsRequest request, ILambdaContext context)
 {
     try
     {
         if (request == null)
         {
             LambdaLogger.Log($"{nameof(request)} was null or empty.");
             return("failed");
         }
         LambdaLogger.Log($"ContactUs Request received and request is : {request}");
         LambdaLogger.Log(JsonConvert.SerializeObject(request));
         if (!IsValidRequest(request))
         {
             return("invalid request");
         }
         var message = RequestMapToSnsEvent(request);
         return(!SendMessage(message) ? "failed" : "success");
     }
     catch (Exception e)
     {
         LambdaLogger.Log(e.Message);
         LambdaLogger.Log(e.StackTrace);
         throw;
     }
 }
コード例 #6
0
        public async Task <IActionResult> AddContactUs([FromBody] ContactUsRequest contactUs)
        {
            var loggedUser = User.GetUserIdFromToken();
            var result     = await _contactUsService.CreateContactUsAsync(loggedUser, contactUs);

            var mapped = _mapper.Map <ContactUsResponse>(result);

            return(Created("", new ApiOkResponse(mapped)));
        }
コード例 #7
0
        public ActionResult <ContactUsResponse> GetGreeting(ContactUsRequest request)
        {
            var response = new ContactUsResponse()
            {
                Message  = $"Hello, {request.Name}, thank you for contacting us, we will be in touch shortly. In the meantime, please verify that {request.Phone} is the correct phone number, if not please send another message to correct.",
                SentDate = DateTime.Now
            };

            return(Ok(response));
        }
コード例 #8
0
        public ActionResult AddContactUsRequest(ContactUsRequest request)
        {
            request.RequestDate = System.DateTime.UtcNow;
            var res = _contactUsRequestService.AddContactUsRequest(request);

            //return RedirectToAction("Home", "Home");
            return(Json(new Response {
                Success = res, Message = res ? Resource.SandSuccessfully : Resource.ErrorsOccurred
            }));
        }
コード例 #9
0
        public ActionResult InsertContactUsRequest(ContactUsRequest request)
        {
            var repo = ContactUsRepositoryFactory.GetRepository();

            if (ModelState.IsValid)
            {
                repo.Insert(request);

                return(RedirectToAction("Index"));
            }

            return(View("Contact", request));
        }
コード例 #10
0
        public void Insert(ContactUsRequest request)
        {
            ContactUsRequest newRequest = new ContactUsRequest();

            var repo = GetAll();

            newRequest.ContactName    = request.ContactName;
            newRequest.ContactEmail   = request.ContactEmail;
            newRequest.ContactPhone   = request.ContactPhone;
            newRequest.ContactMessage = request.ContactMessage;

            repo.Insert(newRequest.ContactUsID, newRequest);
        }
コード例 #11
0
        public async Task ContactUs(ContactUsRequest model)
        {
            /* string htmlContentPath = _env.WebRootPath + "/EmailTemplates/ContactUs.html";
             * string htmlContent = System.IO.File.ReadAllText(htmlContentPath).Replace("{{&message}}", model.Message).Replace("{{&toName}}", model.To);*/
            SendGridMessage message = new SendGridMessage()
            {
                /*From = new EmailAddress("*****@*****.**", "Example User"),*/
                From        = new EmailAddress(model.From, model.Name),
                Subject     = model.Subject,
                HtmlContent = model.Message,
            };

            message.AddTo("*****@*****.**");
            await Send(message);
        }
コード例 #12
0
        public void CanInsertContactUsRequest()
        {
            ContactUsRequest request = new ContactUsRequest();

            var repo = new ContactUsRepositoryDapper();

            request.ContactName    = "Jim Duggin";
            request.ContactEmail   = "*****@*****.**";
            request.ContactPhone   = "111-222-3333";
            request.ContactMessage = "Please call me about the new BMW";

            repo.Insert(request);

            Assert.AreEqual(2, request.ContactUsID);
        }
コード例 #13
0
        public ContactUsRequest Post(ContactUsAddRequest model)
        {
            ContactUsRequest contactusRequest = new ContactUsRequest
            {
                FromEmail = model.Email,
                FromName  = model.Name,
                ToEmail   = _configService.ConvertConfigValue_String("To_Email"),
                Subject   = model.Subject,
                Question  = model.Question,
                ContactUsEmailTemplate = HostingEnvironment.MapPath("~/Content/ContactUsEmailTemplate.html"),
                SendGridKey            = _configService.ConvertConfigValue_String("SendGrid_Key"),
            };

            return(contactusRequest);
        }
        public async Task SendEmailAsyncWhenContactOptionNotContactAdvisorThenAreaRoutingApiAndSharedConfigNotCalled()
        {
            // Arrange
            var sendEmailRequest = new ContactUsRequest {
                ContactOption = "Feedback", Email = "*****@*****.**"
            };
            var service = new FamSendGridEmailService(fakeEmailTemplateRepository, fakeMergeEmailContentService, fakeAuditRepository, fakeSimulateEmailResponsesService, fakeSendGridClient, fakeMapper, fakeHttpClientService, fakeConfigurationProvider, fakeApplicationLogger);

            // Act
            var result = await service.SendEmailAsync(sendEmailRequest).ConfigureAwait(false);

            // Assert
            Assert.True(result);
            A.CallTo(() => fakeHttpClientService.GetAsync(A <string> .Ignored, A <Func <HttpResponseMessage, bool> > .Ignored, A <FaultToleranceType> .Ignored)).MustNotHaveHappened();
        }
コード例 #15
0
        public ActionResult AddProjectRequest(ContactUsRequest request)
        {
            request.ContactUsReasonTextEn = "Project Request";
            request.ContactUsReasonTextAr = "طلب مشروع";
            request.RequestDate           = System.DateTime.UtcNow;
            var res = _contactUsRequestService.AddContactUsRequest(request);

            if (res) //if true  ==> insert the same request to MySql DataBase to Trigger MailService to Send Mail from (MySql DataBase)
            {
                var result = MySQLTransactions.InsertIntoContactUsRequest(request);
            }

            return(Json(new Response {
                Success = res, Message = res ? Resource.SandSuccessfully : Resource.ErrorsOccurred
            }));
        }
コード例 #16
0
        private string RequestMapToSnsEvent(ContactUsRequest request)
        {
            string message = "";

            if (request.RequestFor.Length > 2 && request.RequestFor.ToLower() == "contactus")
            {
                message = ($"We have received contact us request from {request.Firstname} {request.Lastname}.The enquirer Phone Number is {request.PhoneNumber} and" +
                           $" Email Address is {request.EmailAddress}.");
            }

            else if (request.RequestFor.Length > 2 && request.RequestFor.ToLower() == "prayerrequest")
            {
                message = (
                    $"We have received special prayer request from {request.Firstname} {request.Lastname}.The requester Phone Number is {request.PhoneNumber} and" +
                    $" Email Address is {request.EmailAddress}.");
            }
            else if (request.RequestFor.Length > 2 && request.RequestFor.ToLower() == "perunnalshare")
            {
                message = (
                    $"  We have received perunnal share request from {request.Firstname} {request.Lastname}.The requester Phone Number is {request.PhoneNumber} and" +
                    $" Email Address is {request.EmailAddress} No of share is {request.NumberOfShares} for the {request.RequestFor}."
                    );
            }
            else if (request.RequestFor.Length > 2 && request.RequestFor.ToLower() == "onlinegiving")
            {
                message = (
                    $"  We have received Online Giving request from {request.Firstname} {request.Lastname}.The requester Phone Number is {request.PhoneNumber} and" +
                    $" Email Address is {request.EmailAddress} and would like to Donate $:{request.DonationAmount}."
                    );
            }
            else
            {
                message = (
                    $"  We have received qurbana/service request from {request.Firstname} {request.Lastname}.The requester Phone Number is {request.PhoneNumber} and" +
                    $" Email Address is {request.EmailAddress}. The request of the service is {request.RequestFor}."
                    );
            }

            if (!string.IsNullOrEmpty(request.Message))
            {
                message += $"The message from the requester is {request.Message}";
            }

            return(message);
        }
 public MergeEmailContentServiceTests()
 {
     sendEmailRequest = new ContactUsRequest
     {
         TemplateName  = nameof(ContactUsRequest.TemplateName),
         FirstName     = nameof(ContactUsRequest.FirstName),
         LastName      = nameof(ContactUsRequest.LastName),
         Email         = nameof(ContactUsRequest.Email),
         ContactOption = nameof(ContactUsRequest.ContactOption),
         DateOfBirth   = new DateTime(2000, 3, 12),
         Postcode      = nameof(ContactUsRequest.Postcode),
         ContactAdviserQuestionType = nameof(ContactUsRequest.ContactAdviserQuestionType),
         Message              = nameof(ContactUsRequest.Message),
         IsContactable        = true,
         FeedbackQuestionType = nameof(ContactUsRequest.FeedbackQuestionType),
         TermsAndConditions   = true
     };
 }
コード例 #18
0
        public async Task <ActionResult <SuccessResponse> > ContactUsAsync(ContactUsRequest model)
        {
            int          code     = 200;
            BaseResponse response = null;

            try
            {
                await _emailService.ContactUs(model);

                response = new SuccessResponse();
            }
            catch (Exception ex)
            {
                code     = 500;
                response = new ErrorResponse(ex.Message);
            }
            return(StatusCode(code, response));
        }
コード例 #19
0
        public void Insert(ContactUsRequest request)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                var parameters = new DynamicParameters();

                parameters.Add("@ContactUsID",
                               dbType: DbType.Int32, direction: ParameterDirection.Output);
                parameters.Add("@ContactName", request.ContactName);
                parameters.Add("@ContactEmail", request.ContactEmail);
                parameters.Add("@ContactPhone", request.ContactPhone);
                parameters.Add("@ContactMessage", request.ContactMessage);

                cn.Execute("ContactUsInsert",
                           parameters, commandType: CommandType.StoredProcedure);

                request.ContactUsID = parameters.Get <int>("@ContactUsID");
            }
        }
        public async Task SendEmailAsyncWhenContactOptionIsContactAdvisorThenAreaRoutingApiCalled()
        {
            // Arrange
            var sendEmailRequest = new ContactUsRequest {
                ContactOption = "ContactAdviser", Email = DefaultFromEmailAddress
            };
            var service = new FamSendGridEmailService(fakeEmailTemplateRepository, fakeMergeEmailContentService, fakeAuditRepository, fakeSimulateEmailResponsesService, fakeSendGridClient, fakeMapper, fakeHttpClientService, fakeConfigurationProvider, fakeApplicationLogger);

            // Act
            var result = await service.SendEmailAsync(sendEmailRequest).ConfigureAwait(false);

            // Assert
            Assert.True(result);
            A.CallTo(() => fakeHttpClientService.GetAsync(A <string> .Ignored, A <FaultToleranceType> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeSendGridClient.SendEmailAsync(
                         A <SendGridMessage> .That.Matches(
                             msg => msg.Personalizations[0].Tos[0].Email == EmailAddressFromAreaRouting),
                         A <CancellationToken> .Ignored)).MustHaveHappened();
        }
コード例 #21
0
        public async Task SendEmailAsyncTest(ContactUsRequest contactUsRequest, bool isThisSimulation, bool expectation)
        {
            //Assign
            var sendEmailService = new SendGridEmailService(fakeEmailTemplateRepository, fakeMergeEmailContentService, fakeAuditRepository, fakeSimulateEmailResponsesService, fakeSendGridClient, fakeMapper);

            A.CallTo(() => fakeEmailTemplateRepository.GetByTemplateName(A <string> ._)).Returns(string.IsNullOrEmpty(contactUsRequest.TemplateName) ? null : goodEmailTemplate);
            A.CallTo(() => fakeMergeEmailContentService.MergeTemplateBodyWithContent(A <ContactUsRequest> ._, A <string> ._)).Returns(nameof(IMergeEmailContent <ContactUsRequest> .MergeTemplateBodyWithContent));
            A.CallTo(() => fakeSendGridClient.SendEmailAsync(A <SendGridMessage> ._, A <CancellationToken> ._)).Returns(new Response(HttpStatusCode.Accepted, null, null));
            A.CallTo(() => fakeConfiguration.GetConfig <string>(A <string> ._)).Returns(string.Empty);
            A.CallTo(() => fakeSimulateEmailResponsesService.IsThisSimulationRequest(A <string> ._)).Returns(isThisSimulation);
            A.CallTo(() => fakeSimulateEmailResponsesService.SimulateEmailResponse(A <string> ._)).Returns(expectation);
            A.CallTo(() => fakeAuditRepository.CreateAudit(A <ContactUsRequest> ._, A <EmailTemplate> ._, A <SendEmailResponse> ._)).DoesNothing();
            A.CallTo(() => fakeMapper.Map <SendEmailResponse>(A <object> ._)).Returns(A.Dummy <SendEmailResponse>());

            //Act
            var result = await sendEmailService.SendEmailAsync(contactUsRequest);

            //Assert
            result.Should().Be(expectation);
            if (isThisSimulation)
            {
                A.CallTo(() => fakeEmailTemplateRepository.GetByTemplateName(A <string> ._)).MustNotHaveHappened();
                A.CallTo(() => fakeSendGridClient.SendEmailAsync(A <SendGridMessage> ._, A <CancellationToken> ._)).MustNotHaveHappened();
                A.CallTo(() => fakeMergeEmailContentService.MergeTemplateBodyWithContent(A <ContactUsRequest> ._, A <string> ._)).MustNotHaveHappened();
                A.CallTo(() => fakeAuditRepository.CreateAudit(A <ContactUsRequest> ._, A <EmailTemplate> ._, A <SendEmailResponse> ._)).MustNotHaveHappened();
            }
            else
            {
                A.CallTo(() => fakeEmailTemplateRepository.GetByTemplateName(A <string> ._)).MustHaveHappened();
                if (expectation)
                {
                    A.CallTo(() => fakeMergeEmailContentService.MergeTemplateBodyWithContent(A <ContactUsRequest> ._, A <string> ._)).MustHaveHappened(Repeated.Exactly.Twice);
                    A.CallTo(() => fakeSendGridClient.SendEmailAsync(A <SendGridMessage> ._, A <CancellationToken> ._)).MustHaveHappened();
                    A.CallTo(() => fakeAuditRepository.CreateAudit(A <ContactUsRequest> ._, A <EmailTemplate> ._, A <SendEmailResponse> ._)).MustHaveHappened();
                }
                else
                {
                    A.CallTo(() => fakeSendGridClient.SendEmailAsync(A <SendGridMessage> ._, A <CancellationToken> ._)).MustNotHaveHappened();
                    A.CallTo(() => fakeMergeEmailContentService.MergeTemplateBodyWithContent(A <ContactUsRequest> ._, A <string> ._)).MustNotHaveHappened();
                    A.CallTo(() => fakeAuditRepository.CreateAudit(A <ContactUsRequest> ._, A <EmailTemplate> ._, A <SendEmailResponse> ._)).MustNotHaveHappened();
                }
            }
        }
コード例 #22
0
        public static async Task <Response> SendEmail(ContactUsRequest contactusRequest)
        {
            var client = new SendGridClient(contactusRequest.SendGridKey); //sendgrid key
            //locates and reads html template
            var    path = contactusRequest.ContactUsEmailTemplate;
            string contactUsTemplate = File.ReadAllText(path);
            // finds keywords and replace them with user email
            string contactUsWithEmail    = contactUsTemplate.Replace("{email}", contactusRequest.FromEmail);   //ContactUsRequest.Email
            string contactUsWithName     = contactUsWithEmail.Replace("{name}", contactusRequest.FromName);    //ContactUsRequest.FromName
            string contactUsWithQuestion = contactUsWithName.Replace("{question}", contactusRequest.Question); //ContactUsRequest.Question
            //uses items from email request to populate email
            var from             = new EmailAddress(contactusRequest.FromEmail, contactusRequest.FromName);
            var subject          = contactusRequest.Subject;
            var to               = new EmailAddress(contactusRequest.ToEmail);
            var plainTextContent = contactusRequest.Question;
            var htmlContent      = contactUsWithQuestion;
            var msg              = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);

            //sends message
            return(await client.SendEmailAsync(msg));
        }
コード例 #23
0
        public override async Task <bool> SendEmailAsync(ContactUsRequest sendEmailRequest, EmailTemplate template = null)
        {
            if (sendEmailRequest.ContactOption == nameof(ContactOption.ContactAdviser))
            {
                if (template == null)
                {
                    template = emailTemplateRepository.GetByTemplateName(sendEmailRequest.TemplateName);
                }

                try
                {
                    var url       = $"{configuration.GetConfig<string>(Constants.AreaRoutingApiServiceUrl)}?location={sendEmailRequest.Postcode}";
                    var accessKey = configuration.GetConfig <string>(Constants.AreaRoutingApiSubscriptionKey);

                    httpClientService.AddHeader(Constants.OcpApimSubscriptionKey, accessKey);
                    var response = await this.httpClientService.GetAsync(url);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var areaRoutingApiResponse = await response.Content.ReadAsAsync <AreaRoutingApiResponse>();

                        template.To = areaRoutingApiResponse.EmailAddress;
                    }
                }
                catch (LoggedException)
                {
                    return(await base.SendEmailAsync(sendEmailRequest, template).ConfigureAwait(false));
                }

                return(await base.SendEmailAsync(sendEmailRequest, template).ConfigureAwait(false));
            }
            else
            {
                return(await base.SendEmailAsync(sendEmailRequest, null).ConfigureAwait(false));
            }
        }
コード例 #24
0
        public async Task <IActionResult> Post([FromForm] ContactUsRequest contactRequest)
        {
            var contactEmails = (await DatabaseContext.ContactEmails.ToListAsync())
                                .Select(email => new Address(email.Email))
                                .ToList();
            var emailComposer = CreateEmail();

            foreach (var file in  contactRequest.Screenshots)
            {
                var attachment = new Attachment
                {
                    Data        = new MemoryStream(),
                    Filename    = file.FileName,
                    ContentType = file.ContentType
                };
                await file.CopyToAsync(attachment.Data);

                attachment.Data.Position = 0;
                emailComposer.Attach(attachment);
            }
            await emailComposer.SendNewContactRequestEmail(contactEmails, contactRequest);

            return(Ok());
        }
コード例 #25
0
 private bool IsValidRequest(ContactUsRequest request)
 {
     return(request.Firstname.Length > 2 && request.Firstname.Length > 2 && request.PhoneNumber.Length == 10 &&
            request.EmailAddress.Length > 3 && request.RequestFor.Length > 2);
 }
コード例 #26
0
 public static async Task SendNewContactRequestEmail(this IFluentEmail email, List <Address> tosAddresses, ContactUsRequest request)
 {
     var subject = $"CSLabs - New contact request from {request.Email}";
     await email
     .To(tosAddresses)
     .Subject(subject)
     //.AttachFromFilename(contactRequest.UserScreenshot)//possible image attachment
     .UsingTemplateFile("ContactRequest.cshtml", new ContactRequestViewModel
     {
         Body    = request.Message,
         Email   = request.Email,
         Subject = subject
     })
     .SendAsync();
 }
コード例 #27
0
        public ActionResult Contact()
        {
            var model = new ContactUsRequest();

            return(View(model));
        }