public ActionResult changePremadeFormStyle()
        {
            int         formID = Convert.ToInt32(Request["formId"]);
            PreMadeForm form   = _context.PreMadeForms.FirstOrDefault(f => f.id == formID);

            form.StyleId = Convert.ToInt32(Request["style"]);

            _context.Entry(form).State = System.Data.Entity.EntityState.Modified;
            _context.SaveChanges();

            TempData["success"] = "Successfully changed style";

            return(RedirectToAction("preMadeForms"));
        }//changePremadeFormStyle()
        }//newPremadeForm()

        public ActionResult deletePreMadeForm(int id)
        {
            PreMadeForm form = _context.PreMadeForms.FirstOrDefault(f => f.id == id);

            if (form != null)
            {
                _context.PreMadeForms.Remove(form);
                _context.SaveChanges();
            }

            TempData["success"] = "Successfully deleted pre-made form";

            return(RedirectToAction("preMadeForms"));
        }//deletePreMadeForm()
示例#3
0
        }//preMadeForms()

        public ActionResult preMadeFormCode(int id)
        {
            PreMadeForm form = _context.PreMadeForms.Include(p => p.Style).FirstOrDefault(f => f.id == id);

            if (form == null)
            {
                return(View("Error"));
            }
            if (form.Style.id != 1)
            {
                form.Code += "\n\n<style>\n" + form.Style.Code + "\n</style>";
            }

            return(View(form));
        }//preMadeFormCode()
示例#4
0
        public ActionResult customFormPost()
        {
            NameValueCollection nvc = Request.Form;

            StringBuilder code = new StringBuilder();

            if (!string.IsNullOrEmpty(nvc["numberOfSelects"]))
            {
                bool bootstrap = false;
                if (Validation.validate(nvc))
                {
                    if (nvc["cb"] != null)
                    {
                        code.Append(generateWithBootstrap(nvc));
                        bootstrap = true;
                    }
                    else
                    {
                        //generate code without bootstrap
                        code.Append(generateNoBootstrap(nvc));
                    }
                }
                else
                {
                    //validation error
                    return(View("Error"));
                }

                code.Append("</form>");


                string selectedStyle = nvc["styleSelect"].ToString();
                Style  style;
                if (selectedStyle == "/")
                {
                    style = _context.Styles.FirstOrDefault(s => s.Name == "None");
                }
                else
                {
                    style = _context.Styles.FirstOrDefault(s => s.Code == selectedStyle);
                }

                ApplicationUser user = getUser();
                if (user.Email == "*****@*****.**")
                {
                    PreMadeForm form = new PreMadeForm()
                    {
                        Name          = nvc["formName"],
                        Category      = nvc["formCategory"],
                        withBootstrap = bootstrap,
                        Code          = code.ToString(),
                        StyleId       = style.id
                    };

                    if (nvc["free"] != null)
                    {
                        form.Free = true;
                    }
                    else
                    {
                        form.Free = false;
                    }

                    _context.PreMadeForms.Add(form);
                    _context.SaveChanges();
                }


                if (selectedStyle != "/")
                {
                    code.Append("\n\n<style>");
                    code.Append("\n" + style.Code);
                    code.Append("\n</style>");
                }

                if (user.Email != "*****@*****.**")
                {
                    CodeHistory codeHistory = new CodeHistory()
                    {
                        UserId = user.Id,
                        Code   = code.ToString(),
                        Date   = DateTime.Now
                    };

                    _context.CodeHistories.Add(codeHistory);
                    _context.SaveChanges();
                }

                ViewBag.Code = code;

                //success page
                return(View());
            }
            else
            {
                //error
                return(View("Error"));
            }
        }//customFormPost()