コード例 #1
0
        public IActionResult PostForm(IFormCollection collection)
        {
            var path = HttpContext.Request.Path;

            var form = new FormSubmission();

            var recipient = collection
                            .TryGetValue("recipient", out var recipientValue);

            var redirect = collection.TryGetValue("redirect", out var redirectValue);

            if (!recipient || !redirect)
            {
                return(new BadRequestResult());
            }

            foreach (var keyValuePair in collection)
            {
                var key   = keyValuePair.Key;
                var value = keyValuePair.Value;
                form.AddToSubmissions(key, value);
            }

            form.Remove("recipient");
            form.Remove("redirect");

            var json = form.Return()
                       .Serialize();

            EmailService.Send(json, recipientValue);

            var data = new FormData()
            {
                SerializedData = json,
                CreatedAt      = DateTime.Now,
                UpdatedAt      = DateTime.Now
            };

            return(Redirect(redirectValue));
        }
コード例 #2
0
        public IActionResult PostForm(IFormCollection collection)
        {
            var form = new FormSubmission();

            var recipient = collection
                            .TryGetValue("recipient", out var recipientValue);

            var redirect = collection.TryGetValue("redirect", out var redirectValue);

            if (!recipient)
            {
                return(new BadRequestResult());
            }

            foreach (var keyValuePair in collection)
            {
                var key   = keyValuePair.Key;
                var value = keyValuePair.Value;
                form.AddToSubmissions(key, value);
            }

            form.Remove("recipient");
            form.Remove("redirect");

            var json = form.Return()
                       .Serialize();

            EmailService.Send(json, recipientValue);

            if (redirect)
            {
                return(Redirect(redirectValue));
            }

            throw new Exception("The redirect is required as a mandatory field.");
        }