Example #1
0
        public ActionResult Index(projectsViewModel viewModel)
        {
            ActionResult ar;
            var          multiSelect = Request.Form["multiSelect"];
            // multi select
            tblProject tp = new tblProject();

            viewModel.clearMsg();
            project p;

            switch (viewModel.cmd)
            {
            case "query":
                // project article link
                viewModel.errorMsg = loadProjects(ref viewModel);
                ar = View(viewModel);
                break;

            case "add":
                projectEditViewModel tmpVMa = new projectEditViewModel();
                tmpVMa.pageStatus = (int)PAGE_STATUS.ADD;
                TempData["projectEditViewModel"] = tmpVMa;
                ar = RedirectToAction("AddUpdateProject");
                return(ar);

            case "update":
                p = tp.getById(viewModel.singleSelect);
                if (p != null)
                {
                    projectEditViewModel tmpVM = new projectEditViewModel();
                    tmpVM.editModel  = p;
                    tmpVM.pageStatus = (int)PAGE_STATUS.EDIT;
                    TempData["projectEditViewModel"] = tmpVM;
                    ar = RedirectToAction("AddUpdateProject");
                    return(ar);
                }
                viewModel.errorMsg = "error reading this project";
                ar = View(viewModel);
                break;

            case "systems":
                p = tp.getById(viewModel.singleSelect);
                if (p != null)
                {
                    Session["projectId"]   = p.projectId.ToString();
                    Session["projectName"] = p.projectName;
                    ar = RedirectToAction("Systems", "SD");
                    return(ar);
                }
                viewModel.errorMsg = "error reading this project";
                ar = View(viewModel);
                break;

            case "delete":
                //undone !!... (3) delete project delete article also
                if (string.IsNullOrWhiteSpace(multiSelect))
                {
                    viewModel.errorMsg = "please select project(s) to delete";
                }
                else
                {
                    string[] selected = multiSelect.Split(',');
                    foreach (string projectId in selected.ToList())
                    {
                        viewModel.errorMsg += tp.Delete(projectId);
                    }
                    viewModel.errorMsg += tp.SaveChanges();
                    if (string.IsNullOrWhiteSpace(viewModel.errorMsg))
                    {
                        viewModel.successMsg = "successfully deleted";
                    }
                }
                loadProjects(ref viewModel);
                ar = View(viewModel);
                break;

            case "versions":
                ar = RedirectToAction("Index", "ProjectVersion");
                return(ar);

            default:
                ar = View(viewModel);
                break;
            }
            return(ar);
        }
Example #2
0
        public ActionResult AddUpdateProject(projectEditViewModel viewModel)
        {
            ActionResult ar;

            ViewBag.userList = PMdropdownOption.userList();
            string err;

            viewModel.clearMsg();
            switch (viewModel.cmd)
            {
            case "save":
                err = checkForm(viewModel);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ar = View(viewModel);
                    break;
                }
                tblProject tp = new tblProject();
                if (viewModel.pageStatus == (int)PAGE_STATUS.ADD)
                {
                    viewModel.editModel.projectId  = Guid.NewGuid();
                    viewModel.editModel.createtime = DateTime.Now;
                    viewModel.editModel.projectArticleId
                        = Guid.NewGuid();
                    using (var trans = tp.BeginTransaction())
                    {
                        err += tp.Add(viewModel.editModel);
                        err += tp.SaveChanges();
                        err += addProjectArticle(viewModel, tp.GetDbContext());
                        if (err.Length > 0)
                        {
                            trans.Rollback();
                        }
                        else
                        {
                            trans.Commit();
                        }
                        // new project add an article at the root as a directory, article type project
                    }
                    if (err.Length == 0)
                    {
                        viewModel.successMsg = "new project saved";
                        viewModel.pageStatus = (int)PAGE_STATUS.ADDSAVED;
                    }
                    else
                    {
                        viewModel.errorMsg = err;
                    }
                }
                else if (viewModel.pageStatus == (int)PAGE_STATUS.EDIT)
                {
                    err += tp.Update(viewModel.editModel);
                    err += tp.SaveChanges();
                    if (err.Length == 0)
                    {
                        viewModel.successMsg = "project updated";
                        viewModel.pageStatus = (int)PAGE_STATUS.SAVED;
                    }
                    else
                    {
                        viewModel.errorMsg = err;
                    }
                }
                else
                {
                    viewModel.errorMsg = "wrong page status " + viewModel.pageStatus;
                }
                ar = View(viewModel);
                break;

            case "addNew":
                projectEditViewModel tmpVMa = new projectEditViewModel();
                tmpVMa.pageStatus = (int)PAGE_STATUS.ADD;
                TempData["projectEditViewModel"] = tmpVMa;
                ar = RedirectToAction("AddUpdateProject");
                return(ar);

            case "query":
                ar = RedirectToAction("Index");
                return(ar);

            default:
                ar = View(viewModel);
                break;
            }
            return(ar);
        }