protected string queryProjectVersions(ref projectVersionsViewModel viewModel) { string ret = ""; tblProjectVersion tpv = new tblProjectVersion(); projectVersionsViewModel tmpVM = viewModel; var qry = (from a in tpv.getAll() select a).AsQueryable(); if (!string.IsNullOrWhiteSpace(viewModel.projectId)) { qry = qry.Where(x => x.projectId == new Guid(tmpVM.projectId)); } if (!string.IsNullOrWhiteSpace(viewModel.version)) { qry = qry.Where(x => x.version.Contains(tmpVM.version)); } viewModel.projectVersions = qry.ToList(); return(ret); }
public ActionResult Index(projectVersionsViewModel viewModel) { ActionResult ar; var multiSelect = Request.Form["multiSelect"]; ViewBag.projectList = PMdropdownOption.projectList(); viewModel.clearMsg(); tblProjectVersion tpv = new tblProjectVersion(); projectVersionEditViewModel tmpVM; switch (viewModel.cmd) { case "query": viewModel.errorMsg = queryProjectVersions(ref viewModel); ar = View(viewModel); break; case "add": tmpVM = new projectVersionEditViewModel(); tmpVM.pageStatus = (int)PAGE_STATUS.ADD; TempData["projectVersionEditViewModel"] = tmpVM; ar = RedirectToAction("AddUpdate"); return(ar); case "update": projectVersion pv = tpv.getById(viewModel.singleSelect); if (pv != null) { tmpVM = new projectVersionEditViewModel(); tmpVM.editModel = pv; tmpVM.pageStatus = (int)PAGE_STATUS.EDIT; TempData["projectVersionEditViewModel"] = tmpVM; ar = RedirectToAction("AddUpdate"); return(ar); } viewModel.errorMsg = "error reading this project version"; ar = View(viewModel); break; case "delete": //undone !!... (3) delete project delete article also if (string.IsNullOrWhiteSpace(multiSelect)) { viewModel.errorMsg = "please select project version to delete"; } else { string[] selected = multiSelect.Split(','); foreach (string projectVersionS in selected.ToList()) { int projectVersionId; if (!int.TryParse(projectVersionS, out projectVersionId)) { continue; } viewModel.errorMsg += tpv.Delete(projectVersionId); } viewModel.errorMsg += tpv.SaveChanges(); if (string.IsNullOrWhiteSpace(viewModel.errorMsg)) { viewModel.successMsg = "successfully deleted"; } } viewModel.errorMsg = queryProjectVersions(ref viewModel); ar = View(viewModel); break; default: ar = View(viewModel); break; } return(ar); }
public ActionResult AddUpdate(projectVersionEditViewModel viewModel) { ActionResult ar; ViewBag.projectList = PMdropdownOption.projectList(); string err; viewModel.clearMsg(); switch (viewModel.cmd) { case "save": err = checkForm(viewModel); if (err.Length > 0) { viewModel.errorMsg = err; ar = View(viewModel); break; } tblProjectVersion tpv = new tblProjectVersion(); if (viewModel.pageStatus == (int)PAGE_STATUS.ADD) { viewModel.editModel.createtime = DateTime.Now; viewModel.editModel.versionArticleId = Guid.NewGuid(); using (var trans = tpv.BeginTransaction()) { err += tpv.Add(viewModel.editModel); err += tpv.SaveChanges(); err += addProjectVersionArticle(viewModel, tpv.GetDbContext()); if (err.Length > 0) { trans.Rollback(); } else { trans.Commit(); } } if (err.Length == 0) { viewModel.successMsg = "new project version saved"; viewModel.pageStatus = (int)PAGE_STATUS.ADDSAVED; } else { viewModel.errorMsg = err; } } else if (viewModel.pageStatus == (int)PAGE_STATUS.EDIT) { err += tpv.Update(viewModel.editModel); err += tpv.SaveChanges(); if (err.Length == 0) { viewModel.successMsg = "project version update"; viewModel.pageStatus = (int)PAGE_STATUS.SAVED; } else { viewModel.errorMsg = err; } } else { viewModel.errorMsg = "wrong page status " + viewModel.pageStatus; } ar = View(viewModel); break; case "addNew": projectVersionEditViewModel tmpVM = new projectVersionEditViewModel(); tmpVM.pageStatus = (int)PAGE_STATUS.ADD; TempData["projectVersionEditViewModel"] = tmpVM; ar = RedirectToAction("AddUpdate"); return(ar); case "query": ar = RedirectToAction("Index"); return(ar); default: ar = View(viewModel); break; } return(ar); }