private bool isValidInput(formCreateModel formCreate)
 {
     if (!isFormNameValid(formCreate.formName))
     {
         return(false);
     }
     formItemModel[] formItems = formCreate.formItems;
     if (formCreate.formItems == null || formCreate.formItems.Count() == 0)
     {
         addError("Must add at leat 1 field to form.");
         return(false);
     }
     if (formCreate.HasDuplicateItems())
     {
         addError("There are duplicate items with the same input name in form.");
         return(false);
     }
     foreach (formItemModel item in formItems)
     {
         if (!item.isValidItem())
         {
             addError("Field Label  '" + item.fieldLabel + "', Input Name : '" + item.inputName + "', Input Type : '" + item.inputTypeName + "' has invalid inputs.");
             return(false);
         }
     }
     return(true);
 }
        public ActionResult Create(formCreateModel formCreate)
        {
            ViewBag.ErrorDetails = "";
            if (!isValidInput(formCreate))
            {
                return(Json(ViewBag.ErrorDetails));
            }
            string formName = formCreate.formName;

            formItemModel[] arrFormItems = formCreate.formItems;

            int formID = addFormNameToDB(formName);

            for (int pos = 0; pos < arrFormItems.Length; pos++)
            {
                tblInputInForm tblInputInForm = new tblInputInForm(formID, arrFormItems[pos].inputTypeName, pos, arrFormItems[pos].fieldLabel, arrFormItems[pos].inputName, arrFormItems[pos].required);
                db.tblInputInForms.Add(tblInputInForm);
            }
            db.SaveChanges();
            return(Json(""));
        }