public IActionResult SaveContactUs(MContactUs form)
        {
            string token = GetCpatchaToken();

            string validationMessage = ValidateContactUsForm(form, token);

            if (validationMessage != null)
            {
                ViewBag.Message = validationMessage;
            }
            else
            {
                IBusinessOperationManipulate <MContactUs> operation = GetSaveContactUsOperation();
                form.IP      = RemoteUtils.GetRemoteIPAddress(ControllerContext);
                form.Name    = StringUtils.StripTagsRegex(form.Name);
                form.Subject = StringUtils.StripTagsRegex(form.Subject);
                form.Email   = StringUtils.StripTagsRegex(form.Email);
                form.Message = StringUtils.StripTagsRegex(form.Message);

                operation.Apply(form);

                bool sendResult = SendEmail(form, token);

                if (sendResult)
                {
                    ViewBag.Message = "Your message has been received and we will contact you soon.";
                }
                else
                {
                    ViewBag.Message = "Unable to send the message, internal server error.";
                }
            }

            return(View("Contact"));
        }
        public void Setup()
        {
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            controllerContext.HttpContext.Connection.RemoteIpAddress = IPAddress.Parse("127.0.0.1");

            mockController = new Mock <ContactUsController>()
            {
                CallBase = true
            };
            var mockOpr = new Mock <IBusinessOperationManipulate <MContactUs> >();

            mockContactUsOpr = mockOpr.Object;
            mockOpr.Setup(foo => foo.Apply(It.IsAny <MContactUs>())).Returns(0);

            mockController.Setup(foo => foo.GetSaveContactUsOperation()).Returns(mockContactUsOpr);
            var iCacheMock = new Mock <ICacheContext>();

            mockController.Setup(foo => foo.GetContentCache()).Returns(iCacheMock.Object);

            var mockSmtp = new Mock <ISmtpContext>();

            mockController.Setup(foo => foo.GetSmtpContext()).Returns(mockSmtp.Object);

            controller = mockController.Object;
            controller.ControllerContext = controllerContext;

            var values = new Dictionary <string, StringValues>()
            {
                { "g-recaptcha-response", new StringValues("ThisIsFakedToken") }
            };
            var formValues = new FormCollection(values);

            var httpReqMocked = new Mock <HttpRequest>();

            httpReqMocked.Setup(r => r.Form).Returns(formValues);
            var httpReq = httpReqMocked.Object;

            controller.SetHttpRequest(httpReq);
        }
        private IActionResult VerifyProduct(MRegistration param)
        {
            IBusinessOperationManipulate <MRegistration> operation = GetCreateRegistrationOperation();

            try
            {
                operation.Apply(param);
                ViewBag.Serial = param.SerialNumber;
                ViewBag.PIN    = param.Pin;

                LineNotify(param, "Production verification successfully.");

                return(View("Success"));
            }
            catch (Exception e)
            {
                ViewBag.Message = FilterSensitive(e.Message);
                LineNotify(param, e.Message);

                return(View("Fail"));
            }
        }