Exemple #1
0
        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");
            }
        }
 //
 /* Checks to see if the work effort falls within the specified PCA code's time boundaries.
  * If so, it returns TRUE.
  */
 public bool verifyWeTimeBounds(WorkEffort effort, int pca)
 {
     var searchPCA = from m in PcaCodeDB.PcaCodeList
                    where (m.code.CompareTo(pca) == 0)
                    select m;
     foreach (var item in searchPCA)
     {
         if ((item.startDate <= effort.startDate) && (item.endDate >= effort.endDate))
         {
             return true;
         }
     }
     return false;
 }
        public virtual ActionResult editWorkEffort(WorkEffort workeffort)
        {
            Authentication auth = new Authentication();
            if (auth.isManager(this) || Authentication.DEBUG_bypassAuth)
            {
                if (ModelState.IsValid)
                {
                    //make sure the start date is before the end date
                    if (workeffort.startDate > workeffort.endDate)
                    {
                        ViewBag.endBeforeStartFlag = true;
                        ViewBag.pcaList = getWePcaCodesSelectList(workeffort);
                        Authentication newAuth = new Authentication();
                        if (newAuth.isAdmin(this))
                        {
                            ViewBag.adminFlag = true;
                        }
                        return View(workeffort);
                    }

                    //make sure it falls within it's associated PCA code's time boundaries
                    if (verifyWeTimeBounds(workeffort, workeffort.pcaCode) == true)
                    {
                        WorkEffortDB.WorkEffortList.Add(workeffort);
                        WorkEffortDB.Entry(workeffort).State = System.Data.EntityState.Modified;
                        WorkEffortDB.SaveChanges();
                        return RedirectToAction("weManagement");
                    }
                    else
                    {
                        ViewBag.notWithinTimeBounds = true;
                        ViewBag.pcaList = getWePcaCodesSelectList(workeffort);
                        Authentication newAuth = new Authentication();
                        if (newAuth.isAdmin(this))
                        {
                            ViewBag.adminFlag = true;
                        }
                        return View(workeffort);
                    }
                }
                return View(workeffort);
            }
            else
            {
                return View("error");
            }
        }
        // 
        /* 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;
        }
        //
        /* Uses TempData["hoursList"] (assigned by the calling function) to create a list of objects 
         * that each contain number of hours for Sun-Sat for each workEffort/timeCode pairing.  The 
         * list of objects is then returned to the calling function
         */
        public List<TimesheetRow> convertHoursForTimesheetView()
        {
            WorkEffort effort = new WorkEffort();
            string effortDescription = "";
            List<WorkEffort> workEffortList = new List<WorkEffort>();
            List<string> timeCodeList = new List<string>();
            List<string> effortAndCodeConcat = new List<string>();
            List<TimesheetRow> tsRowList = new List<TimesheetRow>();

            //TempData["hoursList"] was assigned in viewTimesheet() before calling this method
            IEnumerable<Hours> hoursList = (IEnumerable<Hours>)TempData["hoursList"];

            //create a list of workEffort/timeCode pairings for the pay period
            foreach (var item in hoursList)
            {
                timeCodeList.Add(item.description);
                effort = WorkEffortDB.WorkEffortList.Find(item.workEffortID);
                if (effort != null)
                {
                    workEffortList.Add(effort);
                    effortAndCodeConcat.Add(effort.description + "::::" + item.description);
                }
            }
            //remove duplicates from the list
            effortAndCodeConcat = effortAndCodeConcat.Distinct().ToList();

            //for each unique workEffort/timeCode pairing
            foreach (var effortAndCode in effortAndCodeConcat)
            {
                TimesheetRow tmpTsRow = new TimesheetRow();

                /* save the work effort description and time code, then remove from the front of the list.
                 * In the process, any duplicate pairs are ignored and removed by comparing to effortAndCodeConcat
                 */
                for (int count = 0; count < 100; count++)
                {
                    try
                    {
                        if ((effortAndCode.Contains(workEffortList.First().description)) &&
                             (effortAndCode.Contains(timeCodeList.First())))
                        {
                            tmpTsRow.weID = workEffortList.First().ID;
                            tmpTsRow.workeffort = workEffortList.First().description;
                            tmpTsRow.timecode = timeCodeList.First();
                            workEffortList.RemoveAt(0);
                            timeCodeList.RemoveAt(0);
                            break;
                        }
                        else
                        {
                            workEffortList.RemoveAt(0);
                            timeCodeList.RemoveAt(0);
                        }
                    }
                    catch
                    {
                    }
                }

                //for each hours entry in the pay period
                foreach (var tmpVal in hoursList)
                {
                    effortDescription = getWeDescription(tmpVal.workEffortID);
                    //if the hours entry belongs to the unique workEffort/timeCode pairing
                    if ((effortAndCode.CompareTo(effortDescription + "::::" + tmpVal.description) == 0))
                    {
                        switch (tmpVal.timestamp.DayOfWeek.ToString())
                        {
                            case ("Sunday"):
                                tmpTsRow.sunHours = tmpVal;
                                break;
                            case ("Monday"):
                                tmpTsRow.monHours = tmpVal;
                                break;
                            case ("Tuesday"):
                                tmpTsRow.tueHours = tmpVal;
                                break;
                            case ("Wednesday"):
                                tmpTsRow.wedHours = tmpVal;
                                break;
                            case ("Thursday"):
                                tmpTsRow.thuHours = tmpVal;
                                break;
                            case ("Friday"):
                                tmpTsRow.friHours = tmpVal;
                                break;
                            case ("Saturday"):
                                tmpTsRow.satHours = tmpVal;
                                break;
                            default:
                                break;
                        }
                    }
                }
                //Add the TimesheetRow so it will be displayed in viewTimesheet View
                tsRowList.Add(tmpTsRow);
            }
            return tsRowList;
        }