コード例 #1
0
        public ActionResult Create(EditProcessViewModel Model)
        {
            Data data = new Data();

            if (ModelState.IsValid && db.Processes.SingleOrDefault(p => p.ProcessName == Model.Process.ProcessName) == null)
            {
                Model.Process.Active = true;
                db.Processes.Add(Model.Process);

                // If any issue is selected
                if (Model.SelectedIssues != null && Model.SelectedIssues.Count() > 0)
                {
                    // Insert a list of Issues as the process Issues where the ID is found within the Issues array
                    Model.Process.Issues = db.Issues.Where(x => Model.SelectedIssues.Contains(x.IssueID.ToString())).ToList();
                }

                // Generate standards for the new product
                // As well as any missing product:process combination
                db.SaveChanges();
                data.GenerateDefaultStandards();

                TempData["Success"] = Model.Process.ProcessName + " has been added";
                return(RedirectToAction("Index", "Manage", new { area = "Admin" }));
            }
            else if (db.Processes.SingleOrDefault(p => p.ProcessName == Model.Process.ProcessName) != null)
            {
                TempData["Error"] = Model.Process.ProcessName + " already exists. Please reactivate the process or give the new process a unique name.";
            }
            else
            {
                TempData["Error"] = "Please use only valid characters in the name field.";
            }
            Model.Issues = data.GetActiveIssues();
            return(View(Model));
        }
コード例 #2
0
        /// <summary>
        /// GET: Admin/Processes/Create
        /// Creates this instance.
        /// </summary>
        /// <returns>ActionResult.</returns>
        public ActionResult Create()
        {
            var data  = new Data();
            var model = new EditProcessViewModel();

            // Do not include Quarantine as an issue since it is automatically appended to the end
            model.Issues = data.GetActiveIssues().Where(x => x.IssueID != 5).ToList();

            return(View(model));
        }
コード例 #3
0
        /// <summary>
        /// GET: Admin/Processes/Edit
        /// Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>ActionResult.</returns>
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Process process = db.Processes.Find(id);

            var data  = new Data();
            var model = new EditProcessViewModel();

            model.Process = process;
            // Do not include Quarantine as an issue since it is automatically appended to the end
            model.Issues = data.GetActiveIssues().Where(x => x.IssueID != 5).ToList();

            return(View(model));
        }
コード例 #4
0
        public ActionResult Edit(EditProcessViewModel Model)
        {
            // Look up existing processes based on the ProcessID that was passed through as a hidden field
            var process = db.Processes.Find(Model.Process.ProcessID);

            String[] issues = process.Issues.Select(x => x.IssueID.ToString()).ToArray();
            var      d      = new Data();

            if (!ModelState.IsValid)
            {
                Model.Process        = process;
                Model.Issues         = d.GetActiveIssues();
                Model.SelectedIssues = issues;
                return(View(Model));
            }

            // If we find that process indeed exists
            if (process != null)
            {
                bool duplicateProcessFound = false;
                foreach (Process p in d.GetProcesses())
                {
                    if (p.ProcessID == process.ProcessID)
                    {
                        continue;
                    }
                    else
                    {
                        if (p.ProcessName == Model.Process.ProcessName)
                        {
                            duplicateProcessFound = true;
                        }
                    }
                }
                // Check to see if the ProcessName has been changed
                if (!duplicateProcessFound)
                {
                    // Name has changed and doesn't exist.
                    // Set the existing process' name to the new name
                    process.ProcessName = Model.Process.ProcessName;
                    TempData["Sucess"]  = "Here";
                }
                else
                {
                    TempData["Error"] = "Process name already exists. Please provide a unique Process name.";

                    Model.Process = process;
                    Model.Issues  = d.GetActiveIssues();

                    Model.SelectedIssues = issues;
                    return(View(Model));
                }

                // Clear existing issues from the production so that we may associate any selected issue
                process.Issues.Clear();
                //String Issues = "";

                // If any issue is selected
                if (Model.SelectedIssues != null && Model.SelectedIssues.Count() > 0)
                {
                    // Insert a list of Issues as the process Issues where the ID is found within the Issues array
                    process.Issues = db.Issues.Where(x => Model.SelectedIssues.Contains(x.IssueID.ToString())).ToList();
                }

                db.Entry(process).State = EntityState.Modified;
                db.SaveChanges();

                TempData["Success"] = "Process updated";
                return(RedirectToAction("Index", "Manage"));
            }

            // Fillout the lists if we need to return to the update view
            Model.Issues         = d.GetActiveIssues();
            Model.SelectedIssues = issues;

            TempData["Error"] = "Process not updated";
            return(View(Model));
        }