//
 // Retrieves the PcaCode object with the specified code and returns the object
 public PcaCode getPcaObjFromCode(int pcacode)
 {
     PcaCode pcaCodeObj = new PcaCode();
     var searchPca = from m in PcaCodeDB.PcaCodeList
                    where m.code == pcacode
                    select m;
     foreach (var item in searchPca)
     {
         pcaCodeObj = item;
     }
     if (pcaCodeObj != null)
     {
         return pcaCodeObj;
     }
     else
     {
         return null;
     }
 }
        // 
        /* Retrieves all PCA codes associated with the specified work effort and 
         * returns them in a string, separated by commas
         */
        public virtual string getWePcaCodesString(int weID)
        {
            PcaCode tmpPca = new PcaCode();
            string pcaString = "";
            WorkEffort we = WorkEffortDB.WorkEffortList.Find(weID);

            var searchPcaWe = from p in PCA_WEDB.PCA_WEList
                              where p.WE == we.ID
                              where p.active == true
                              select p;
            foreach (var item in searchPcaWe)
            {
                tmpPca = PcaCodeDB.PcaCodeList.Find(item.PCA);
                pcaString = pcaString + " " + tmpPca.code + ",";
            }
            pcaString = pcaString.TrimEnd(',');
            return pcaString;
        }
        // 
        /* Retrieves all non-hidden Work Efforts within the specified division, then returns 
         * them as a selection list. Since the division is not stored with a Work Effort, the
         * PCA Codes associated with each Work Effort instance must be retrieved.  If at 
         * least one PCA Code is from the specified division, then the Work Effort is added
         * to the selection list.
         */
        public virtual List<SelectListItem> getVisibleWorkEffortSelectList(string division)
        {
            List<SelectListItem> effortList = new List<SelectListItem>();
            PcaCode tmpPca = new PcaCode();
            string tmpValue = "";

            var searchEfforts = from m in WorkEffortDB.WorkEffortList
                                select m;
            //narrow down to work efforts in the specified division
            //(PCA codes and PCA_WE must be used to get all work efforts in the division)
            foreach (var we in searchEfforts)
            {
                if (we.hidden != true)
                {
                    var searchPcaWe = from p in PCA_WEDB.PCA_WEList
                                        where p.WE == we.ID
                                        where p.active == true
                                        select p;
                    foreach (var pca_we in searchPcaWe)
                    {
                        tmpPca = PcaCodeDB.PcaCodeList.Find(pca_we.PCA);
                        //if the PCA is in the user's division, then add the Work Effort to the list
                        if (tmpPca.division.CompareTo(division) == 0)
                        {
                            tmpValue = we.ID.ToString();
                            effortList.Add(new SelectListItem
                            {
                                Text = we.description,
                                Value = tmpValue
                            });
                            break;
                        }
                    }
                }
            }
            return effortList;
        }
        // 
        /* Retrieves all PCA codes associated with the specified work effort and returns
         * them as a selection list
         */
        public virtual List<SelectListItem> getWePcaCodesSelectList(WorkEffort we)
        {
            List<SelectListItem> pcaList = new List<SelectListItem>();
            PcaCode tmpPca = new PcaCode();

            var searchPcaWe = from p in PCA_WEDB.PCA_WEList
                              where p.WE == we.ID
                              where p.active == true
                              select p;
            foreach (var item in searchPcaWe)
            {
                tmpPca = PcaCodeDB.PcaCodeList.Find(item.PCA);
                pcaList.Add(new SelectListItem
                {
                    Text = tmpPca.code + " (" + tmpPca.division + ")",
                    Value = tmpPca.code.ToString()
                });
            }
            return pcaList;
        }
Exemple #5
0
        public virtual ActionResult addPCA(PcaCode pcacode)
        {
            Authentication auth = new Authentication();
            if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth)
            {
                if (ModelState.IsValid)
                {
                    if (pcacode.endDate == null)
                    {
                        pcacode.endDate = DateTime.MaxValue;
                    }
                    //make sure the start date is before the end date
                    if (pcacode.startDate > pcacode.endDate)
                    {
                        ViewBag.endBeforeStartFlag = true;
                        ViewBag.divisionList = getDivisionSelectList();
                        return View(pcacode);
                    }

                    /* Make sure that the dates don't overlap if there is another PCA with the same
                     * code in the same division
                     */
                    if (pcaCheckIfDuplicate(pcacode) == false)
                    {
                        PcaCodeDB.PcaCodeList.Add(pcacode);
                        PcaCodeDB.SaveChanges();
                        return RedirectToAction("maintainPCA");
                    }
                    else
                    {
                        ViewBag.duplicatePcaFlag = true;
                        ViewBag.divisionList = getDivisionSelectList();
                        return View(pcacode);
                    }
                }
                return View(pcacode);
            }
            else
            {
                return View("error");
            }
        }
Exemple #6
0
 //
 /* Receives a PcaCode object and checks if its 5-digit code already exists in the 
  * division.  If so, it checks if the start and end dates overlap and returns TRUE
  * if they do, FALSE if they don't.
  */
 public bool pcaCheckIfDuplicate(PcaCode pca)
 {
     bool existsFlag = false;
     var searchPca = from p in PcaCodeDB.PcaCodeList
                     where p.ID != pca.ID
                     where p.code == pca.code
                     where (p.division.CompareTo(pca.division) == 0) 
                     select p;
     foreach (var item in searchPca)
     {
         //if the date ranges overlap, then set flag to TRUE
         if ( (pca.startDate <= item.endDate)&&(item.startDate <= pca.endDate) )
         {
             existsFlag = true;
         }
     }
     return existsFlag;
 }
Exemple #7
0
        public virtual ActionResult confirmEditPCA(PcaCode pcacode)
        {
            Authentication auth = new Authentication();
            if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth)
            {

                if (ModelState.IsValid)
                {
                    PcaCodeDB.PcaCodeList.Add(pcacode);
                    PcaCodeDB.Entry(pcacode).State = System.Data.EntityState.Modified;
                    PcaCodeDB.SaveChanges();
                }
                return RedirectToAction("maintainPCA");
            }
            else
            {
                return View("error");
            }
        }
Exemple #8
0
        public virtual ActionResult editPCA(PcaCode pcacode)
        {
            Authentication auth = new Authentication();
            if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth)
            {
                //make sure startDate is prior to endDate 
                if (pcacode.startDate > pcacode.endDate)
                {
                    ViewBag.endBeforeStartFlag = true;
                    ViewBag.divisionList = getDivisionSelectList();
                    return View(pcacode);
                }
                
                /* Make sure that the dates don't overlap if there is another PCA with the same
                 * code in the same division
                 */
                if (pcaCheckIfDuplicate(pcacode) == true)
                {
                    ViewBag.duplicatePcaFlag = true;
                    ViewBag.divisionList = getDivisionSelectList();
                    return View(pcacode);
                }

                TempData["tmpPcaCode"] = pcacode;
                return RedirectToAction("confirmEditPCA");
            }
            else
            {
                return View("error");
            }
        }