Example #1
0
        public ActionResult Create(Template template)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                    return RedirectToAction("Validate", "Login");
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                    ViewData["txtIsAdmin"] = "true";
                else
                    ViewData["txtIsAdmin"] = "false";

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    template = FillNulls(template);
                    template.AccountID = Convert.ToInt32(Session["UserAccountID"]);
                    template.TemplateGUID = Guid.NewGuid();

                    // Set the rows and columns from the drop downs
                    template.Rows = Convert.ToInt32(Request.Form["lstRow"].ToString().Trim());
                    template.Columns = Convert.ToInt32(Request.Form["lstColumn"].ToString().Trim());

                    string validation = ValidateInput(template);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["RowList"] = new SelectList(BuildRowList(), "Value", "Text", Request.Form["lstRow"].ToString().Trim());
                        ViewData["ColumnList"] = new SelectList(BuildColumnList(), "Value", "Text", Request.Form["lstColumn"].ToString().Trim());
                        ViewData["Row1Height"] = Request.Form["txtRow1Height"].ToString().Trim();
                        ViewData["Row2Height"] = Request.Form["txtRow2Height"].ToString().Trim();
                        ViewData["Row3Height"] = Request.Form["txtRow3Height"].ToString().Trim();
                        ViewData["Row4Height"] = Request.Form["txtRow4Height"].ToString().Trim();
                        ViewData["Row5Height"] = Request.Form["txtRow5Height"].ToString().Trim();
                        ViewData["Row6Height"] = Request.Form["txtRow6Height"].ToString().Trim();
                        ViewData["Column1Width"] = Request.Form["txtColumn1Width"].ToString().Trim();
                        ViewData["Column2Width"] = Request.Form["txtColumn2Width"].ToString().Trim();
                        ViewData["Column3Width"] = Request.Form["txtColumn3Width"].ToString().Trim();
                        ViewData["Column4Width"] = Request.Form["txtColumn4Width"].ToString().Trim();
                        ViewData["Column5Width"] = Request.Form["txtColumn5Width"].ToString().Trim();
                        ViewData["Column6Width"] = Request.Form["txtColumn6Width"].ToString().Trim();

                        return View(template);
                    }
                    else
                    {
                        repository.CreateTemplate(template);

                        // Create all the rows and columns
                        ITemplateRowRepository rowrepository = new EntityTemplateRowRepository();
                        for (int r = 1; r <= template.Rows; r += 1)
                        {
                            TemplateRow trow = new TemplateRow();
                            trow.TemplateID = template.TemplateID;
                            trow.RowNumber = r;
                            if (r == 1) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow1Height"]);
                            else if (r == 2) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow2Height"]);
                            else if (r == 3) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow3Height"]);
                            else if (r == 4) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow4Height"]);
                            else if (r == 5) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow5Height"]);
                            else if (r == 6) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow6Height"]);
                            rowrepository.CreateTemplateRow(trow);
                        }

                        ITemplateColumnRepository colrepository = new EntityTemplateColumnRepository();
                        for (int c = 1; c <= template.Columns; c += 1)
                        {
                            TemplateColumn tcol = new TemplateColumn();
                            tcol.TemplateID = template.TemplateID;
                            tcol.ColumnNumber = c;
                            if (c == 1) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn1Width"]);
                            else if (c == 2) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn2Width"]);
                            else if (c == 3) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn3Width"]);
                            else if (c == 4) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn4Width"]);
                            else if (c == 5) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn5Width"]);
                            else if (c == 6) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn6Width"]);
                            colrepository.CreateTemplateColumn(tcol);
                        }

                        CommonMethods.CreateActivityLog((User)Session["User"], "Template", "Add",
                            "Added screen template '" + template.TemplateName + "' - ID: " + template.TemplateID.ToString());

                        return RedirectToAction("Index", "Template");
                    }
                }
                return View(template);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Template", "Create POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
Example #2
0
        public ActionResult Create(Template template)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    template              = FillNulls(template);
                    template.AccountID    = Convert.ToInt32(Session["UserAccountID"]);
                    template.TemplateGUID = Guid.NewGuid();

                    // Set the rows and columns from the drop downs
                    template.Rows    = Convert.ToInt32(Request.Form["lstRow"].ToString().Trim());
                    template.Columns = Convert.ToInt32(Request.Form["lstColumn"].ToString().Trim());

                    string validation = ValidateInput(template);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["RowList"]           = new SelectList(BuildRowList(), "Value", "Text", Request.Form["lstRow"].ToString().Trim());
                        ViewData["ColumnList"]        = new SelectList(BuildColumnList(), "Value", "Text", Request.Form["lstColumn"].ToString().Trim());
                        ViewData["Row1Height"]        = Request.Form["txtRow1Height"].ToString().Trim();
                        ViewData["Row2Height"]        = Request.Form["txtRow2Height"].ToString().Trim();
                        ViewData["Row3Height"]        = Request.Form["txtRow3Height"].ToString().Trim();
                        ViewData["Row4Height"]        = Request.Form["txtRow4Height"].ToString().Trim();
                        ViewData["Row5Height"]        = Request.Form["txtRow5Height"].ToString().Trim();
                        ViewData["Row6Height"]        = Request.Form["txtRow6Height"].ToString().Trim();
                        ViewData["Column1Width"]      = Request.Form["txtColumn1Width"].ToString().Trim();
                        ViewData["Column2Width"]      = Request.Form["txtColumn2Width"].ToString().Trim();
                        ViewData["Column3Width"]      = Request.Form["txtColumn3Width"].ToString().Trim();
                        ViewData["Column4Width"]      = Request.Form["txtColumn4Width"].ToString().Trim();
                        ViewData["Column5Width"]      = Request.Form["txtColumn5Width"].ToString().Trim();
                        ViewData["Column6Width"]      = Request.Form["txtColumn6Width"].ToString().Trim();

                        return(View(template));
                    }
                    else
                    {
                        repository.CreateTemplate(template);

                        // Create all the rows and columns
                        ITemplateRowRepository rowrepository = new EntityTemplateRowRepository();
                        for (int r = 1; r <= template.Rows; r += 1)
                        {
                            TemplateRow trow = new TemplateRow();
                            trow.TemplateID = template.TemplateID;
                            trow.RowNumber  = r;
                            if (r == 1)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow1Height"]);
                            }
                            else if (r == 2)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow2Height"]);
                            }
                            else if (r == 3)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow3Height"]);
                            }
                            else if (r == 4)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow4Height"]);
                            }
                            else if (r == 5)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow5Height"]);
                            }
                            else if (r == 6)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow6Height"]);
                            }
                            rowrepository.CreateTemplateRow(trow);
                        }

                        ITemplateColumnRepository colrepository = new EntityTemplateColumnRepository();
                        for (int c = 1; c <= template.Columns; c += 1)
                        {
                            TemplateColumn tcol = new TemplateColumn();
                            tcol.TemplateID   = template.TemplateID;
                            tcol.ColumnNumber = c;
                            if (c == 1)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn1Width"]);
                            }
                            else if (c == 2)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn2Width"]);
                            }
                            else if (c == 3)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn3Width"]);
                            }
                            else if (c == 4)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn4Width"]);
                            }
                            else if (c == 5)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn5Width"]);
                            }
                            else if (c == 6)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn6Width"]);
                            }
                            colrepository.CreateTemplateColumn(tcol);
                        }

                        CommonMethods.CreateActivityLog((User)Session["User"], "Template", "Add",
                                                        "Added screen template '" + template.TemplateName + "' - ID: " + template.TemplateID.ToString());

                        return(RedirectToAction("Index", "Template"));
                    }
                }
                return(View(template));
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Template", "Create POST", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }