Пример #1
0
        public ActionResult Index(MyStandardPage currentPage, MyFormData myFormData)
        {
            // Manipulate with the ModelState and/or do different stuff if items are valid or not
            var validatedItems = Validate(currentPage, myFormData);

            return(View(currentPage));
        }
Пример #2
0
        public ActionResult Index()
        {
            // We can initialize our form via the associated model
            var myData = new MyFormData {
                SomeValue = "3"
            };

            return(View(myData));
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            MyFormData data = GetData(id);

            string initialData = JsonConvert.SerializeObject(data);

            ViewBag.formMetadataUrl = Url.RouteUrl("api", new { controller = "Home", action = "FormMetadata" });

            return(View((object)initialData));
        }
Пример #4
0
        public ActionResult Index(MyFormData myData)
        {
            // We do (or initiate) our form data processing here
            // We can get the framework to do data validation for us, but that's beyond the scope of this example.
            Debug.WriteLine("Name = {0}, IsTrue = {1}, SomeValue = {2}", myData.Name, myData.IsTrue, myData.SomeValue);

            // Done... we choose to redirect to a new page.
            // In this example, we redirect back to ourself. This will call the Get method for our page (will have the appearance of resetting the form).
            var path = VirtualPathUtility.ToAbsolute("~/");

            return(Redirect(path));
        }
Пример #5
0
        public ActionResult Load(int?id)
        {
            MyFormData data;

            if (id.HasValue)
            {
                data = GetData(id.Value);
            }
            else
            {
                data = new MyFormData();
            }

            string initialData = JsonConvert.SerializeObject(data);

            return(Content(initialData, "application/json"));
        }
Пример #6
0
        public ActionResult Save(MyFormData data)
        {
            IControlGroup fd = MyFormMetadata.GetMetadata();

            MkoForms.Validators.ControlGroupValidator.Validate(data, fd);


            var r = new FormSaveReply();

            if (data.lastName == "Fail")
            {
                r.isFailure      = true;
                r.failureMessage = "Nie udało się zapisać zmian, błąd na żądanie użytkownika.";
            }
            else if (data.lastName == "Error")
            {
                r.isError = true;
                r.errors  = new string[] { "Wartość jest niewystarczająca.", "Podane wartości są bez sensu!" };

                r.propertyErrors = new Dictionary <string, object>();
                r.propertyErrors["notifyViaMail"]        = "In %s you must allow notifying by mail";
                r.propertyErrors["extraPerson.lastName"] = "In %s the name seems suspicious.";
                r.propertyErrors["recipients.0"]         = "W polu %s wartość jest brzydka.";
                r.propertyErrors["contacts.0.firstName"] = new string[] { "W polu %s mamy pierwszy błąd.", "W polu %s mamy też błąd kolejny" };

                int    lastIndex = data.contacts.Length - 1;
                string path      = string.Format("contacts.{0}.lastName", lastIndex);
                r.propertyErrors[path] = "In %s we have an error added dynamically";
            }
            else
            {
                r.isSuccess = true;
            }


            var rs = JsonConvert.SerializeObject(r, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(Content(rs, "application/json"));
        }
Пример #7
0
        private static IList <bool> Validate(MyStandardPage currentPage, MyFormData model)
        {
            var validatedItems = new List <bool>();

            if (currentPage.MainContentArea == null)
            {
                return(validatedItems);
            }

            var items = currentPage.MainContentArea.Items;

            foreach (var content in items)
            {
                var block = content.GetContent();

                if (block == null)
                {
                    continue;
                }

                var input = block as IDynamicField;

                if (input == null)
                {
                    continue;
                }

                var validator = input.GetValidator();

                if (validator == null)
                {
                    continue;
                }

                validatedItems.Add(validator.IsValid(model, input.IsRequired));
            }

            return(validatedItems);
        }