Exemplo n.º 1
0
        public IActionResult Contacts_Submit(ContactUsMessageData messageData)
        {
            if (!ModelState.IsValid)
            {
                return(View(ViewNameContacts, messageData));
            }

            // санитайзер
            var sanitizer        = new HtmlSanitizer();
            var nameSanitized    = sanitizer.Sanitize(messageData.CustomerName);
            var emailSanitized   = sanitizer.Sanitize(messageData.CustomerEmail);
            var subjectSanitized = sanitizer.Sanitize(messageData.EmailSubject);
            var messageSanitized = sanitizer.Sanitize(messageData.EmailMessage);

            if (string.IsNullOrWhiteSpace(nameSanitized))
            {
                var msg = @DbRes.T("CustomerName_Text", ResourceSet);
                ModelState.AddModelError(string.Empty, msg);
                return(View(ViewNameContacts, messageData));
            }

            if (string.IsNullOrWhiteSpace(emailSanitized))
            {
                var msg = @DbRes.T("CustomerEmail_Hint", ResourceSet);
                ModelState.AddModelError(string.Empty, msg);
                return(View(ViewNameContacts, messageData));
            }

            if (!EMailValidator.IsValid(emailSanitized))
            {
                var msg = @DbRes.T("CustomerEmail_Invalid", ResourceSet);
                ModelState.AddModelError(string.Empty, msg);
                return(View(ViewNameContacts, messageData));
            }

            if (string.IsNullOrWhiteSpace(subjectSanitized))
            {
                var msg = @DbRes.T("Subject_Hint", ResourceSet);
                ModelState.AddModelError(string.Empty, msg);
                return(View(ViewNameContacts, messageData));
            }

            if (string.IsNullOrWhiteSpace(messageSanitized))
            {
                var msg = @DbRes.T("Message_Text", ResourceSet);
                ModelState.AddModelError(string.Empty, msg);
                return(View(ViewNameContacts, messageData));
            }

            var rc = DbHelper.ContactsEMailRegister(nameSanitized, emailSanitized, subjectSanitized, messageSanitized, out string errMsg);

            if (!rc)
            {
                ModelState.AddModelError(string.Empty, errMsg);
                return(View(ViewNameContacts, messageData));
            }

            TempData["Message"] = "Yours message was registered successfully";
            return(RedirectToAction("Info", "Home"));
        }
Exemplo n.º 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (SessionManager.QuizResult == null)
            {
                return;
            }
            EMailValidator.Validate();
            RequiredEmailValidator.Validate();
            RequireddpDateMin.Validate();
            RequiredtxtName.Validate();
            if (EMailValidator.IsValid &&
                RequiredEmailValidator.IsValid &&
                RequireddpDateMin.IsValid &&
                RequiredtxtName.IsValid)
            {
                new Services.AdminManager().SaveReport(new BO.ReportQuery()
                {
                    CrudAction = "C",
                    Name       = txtName.Text,
                    Email      = txtEmailAddress.Text,
                    BirthDay   = dpDateMin.Text,
                    Result     = SessionManager.QuizResult.PrintingData3.Result
                });

                SessionManager.QuizResult.PrintingData3.Name = txtName.Text;

                List <PrintingData3> results = new List <PrintingData3>();
                results.Add(SessionManager.QuizResult.PrintingData3);
                string FilePath = new Services.PrintManager().PrintResult3(results, SessionManager.QuizResult.briefs);
                SessionManager.QuizResult.FilePath = FilePath;

                //
                Mailing         mail = new Mailing(txtEmailAddress.Text);
                List <string>[] list = new List <string> [2];
                list[0] = new List <string>()
                {
                    "Name", "Birth Day", "Result"
                };
                list[1] = new List <string>()
                {
                    txtName.Text, dpDateMin.Text, SessionManager.QuizResult.PrintingData3.Result
                };
                string fileName = HttpContext.Current.Server.MapPath("~/Report/Pdf/") + SessionManager.QuizResult.FilePath;
                //
                txtMessage1.Text           = mail.SendQuiz("test result ", fileName, list);
                printHyperLink.Text        = "Download Result";
                printHyperLink.NavigateUrl = "/ReportHandler.ashx?fileName=" + SessionManager.QuizResult.FilePath;
                //
                SessionManager.FreeSurveyResult = null;
                txtName.Enabled         = false;
                dpDateMin.Enabled       = false;
                txtEmailAddress.Enabled = false;
                btnSubmit.Enabled       = false;
            }
        }
Exemplo n.º 3
0
        public void EMailValidator_ThrowsOnNullValue()
        {
            var target = new EMailValidator();

            target.Validate("test", null);
        }
Exemplo n.º 4
0
        public void EMailValidator_ThrowsOnInvalidEmail()
        {
            var target = new EMailValidator();

            target.Validate("test", "ThisShouldFail");
        }
Exemplo n.º 5
0
        public void EMailValidator_WorksCorrectly()
        {
            var target = new EMailValidator();

            target.Validate("test", "*****@*****.**");
        }