public virtual ActionResult addWorkEffort(WorkEffort workeffort) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { if (ModelState.IsValid) { //make sure there is an end date if (workeffort.endDate == null) { workeffort.endDate = DateTime.MaxValue; } //make sure the start date is before the end date if (workeffort.startDate > workeffort.endDate) { ViewBag.divisionList = getDivisionSelectList(); ViewBag.endBeforeStartFlag = true; return(View(workeffort)); } //make sure it falls within it's associated PCA code's time boundaries if (verifyWeTimeBounds(workeffort, workeffort.pcaCode) == true) { //update WorkEffort table in database WorkEffortDB.WorkEffortList.Add(workeffort); WorkEffortDB.SaveChanges(); //add the PCA_WE association to PCA_WE table PCA_WE tmpPcaWe = new PCA_WE(); tmpPcaWe.WE = workeffort.ID; tmpPcaWe.PCA = getPcaIdFromCode(workeffort.pcaCode); tmpPcaWe.associationStartDate = DateTime.Now; tmpPcaWe.associationEndDate = DateTime.MaxValue; tmpPcaWe.active = true; PCA_WEDB.PCA_WEList.Add(tmpPcaWe); PCA_WEDB.SaveChanges(); return(RedirectToAction("weManagement")); } else { ViewBag.divisionList = getDivisionSelectList(); ViewBag.notWithinTimeBounds = true; return(View(workeffort)); } } return(View("error")); } else { return(View("error")); } }
public virtual ActionResult deletePCA_WE(PCA_WE pca_we) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { //The view actually passed the PCA code instead of the ID, so set the ID to the correct value pca_we.PCA = getPcaIdFromCode(pca_we.PCA); int count = 0; PCA_WE tmpPcaWe = new PCA_WE(); var searchPcaWe = from p in PCA_WEDB.PCA_WEList where p.WE == pca_we.WE where p.active == true select p; foreach (var item in searchPcaWe) { //This if-statement will only be true once if (item.PCA == pca_we.PCA) { tmpPcaWe = PCA_WEDB.PCA_WEList.Find(item.ID); } count++; } if (count > 1) { //deactivate and set the end date for the PCA_WE entry tmpPcaWe.active = false; tmpPcaWe.associationEndDate = DateTime.Now; // save changes in database PCA_WEDB.Entry(tmpPcaWe).State = System.Data.EntityState.Modified; PCA_WEDB.SaveChanges(); return(RedirectToAction("weManagement", "Manager")); } ViewBag.lastPcaFlag = true; WorkEffort we = WorkEffortDB.WorkEffortList.Find(pca_we.WE); ViewBag.workEffortDescription = we.description; ViewBag.workEffortId = we.ID; ViewBag.pcaList = getWePcaCodesSelectList(we); return(View()); } else { return(View("error")); } }
// // Changes active status to FALSE for all PCA_WE entries for the specified Work Effort. // Also changes "associationEndDate" to the current day and time public void deactivateAllPcaWeForWorkEffort(int id) { List <PCA_WE> tmpPcaWe = new List <PCA_WE>(); var searchPcaWe = from p in PCA_WEDB.PCA_WEList where p.WE == id select p; tmpPcaWe.AddRange(searchPcaWe); foreach (var item in tmpPcaWe) { item.active = false; item.associationEndDate = DateTime.Now; //save changes in the database PCA_WEDB.Entry(item).State = System.Data.EntityState.Modified; PCA_WEDB.SaveChanges(); } return; }
public virtual ActionResult addPCA_WE(PCA_WE pca_we) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { //The view actually passed the PCA code instead of the ID, so set the ID to the correct value pca_we.PCA = getPcaIdFromCode(pca_we.PCA); WorkEffort effort = WorkEffortDB.WorkEffortList.Find(pca_we.WE); ViewBag.workEffortDescription = effort.description; PcaCode pcaObj = PcaCodeDB.PcaCodeList.Find(pca_we.PCA); //make sure it falls within it's associated PCA code's time boundaries if (verifyWeTimeBounds(effort, pcaObj.code) == true) { //Make sure it's not a duplicate entry before adding to database if (checkIfDuplicatePcaWe(pca_we) == false) { //update PCA_WE table PCA_WEDB.PCA_WEList.Add(pca_we); PCA_WEDB.Entry(pca_we).State = System.Data.EntityState.Added; PCA_WEDB.SaveChanges(); } return(RedirectToAction("editWorkEffort", "Manager", new { id = pca_we.WE })); } ViewBag.divisionList = getDivisionSelectList(); ViewBag.workEffortId = effort.ID; ViewBag.outOfPcaTimeBounds = true; return(View(pca_we)); } else { return(View("error")); } }