// /* Retrieves all PcaCode objects for the specified division and sends them to the * view as a list, along with a division selection list (for narrowing results) * and current division name. */ public ActionResult maintainPCA(string division = null) { Authentication auth = new Authentication(); if(auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { ViewBag.divisionList = getDivisionSelectList(); if (TempData["failedPcaDelete"] != null) { ViewBag.failedPcaDelete = true; } if ((division == null) || (division.CompareTo("All") == 0)) { ViewBag.division = "All"; return View(PcaCodeDB.PcaCodeList.ToList()); } else { ViewBag.division = division; var pcaList = from p in PcaCodeDB.PcaCodeList where (p.division.CompareTo(division) == 0) select p; return View(pcaList.ToList()); } } else { return View("error"); } }
public virtual bool addHours(Hours newhours) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { WorkEffort tmpWe = WorkEffortDB.WorkEffortList.Find(newhours.workEffortID); //make sure that the new hours are within the work effort's time bounds if ((newhours.timestamp < tmpWe.startDate) || (newhours.timestamp > tmpWe.endDate)) { return false; } //make sure that a timesheet exists for the period hours are being added to checkForTimesheet(newhours.creator, newhours.timestamp); //add and save new hours HoursDB.HoursList.Add(newhours); HoursDB.SaveChanges(); return true; } else { return false; } }
// /* Retrieves all PCA codes for the specified division and sends them to the view as * a list. The division name and a division selection list are also sent to the view. */ public virtual ActionResult searchPCA(string division = null) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { ViewBag.divisionList = getDivisionSelectList(); if ( (division == null)||(division.CompareTo("All") == 0) ) { ViewBag.division = "All"; return View(PcaCodeDB.PcaCodeList.ToList()); } else { ViewBag.division = division; var pcaList = from p in PcaCodeDB.PcaCodeList where (p.division.CompareTo(division) == 0) select p; return View(pcaList.ToList()); } } else { return View("error"); } }
// /* Retrieves all the employee objects of employees that work for the specified departement * within the Information Technology division (as per client request), then returns them * as a list. If department is null, it displays all employees in the division */ public virtual ActionResult userManagement(DateTime refDate, string department = null) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { //if it's a redirect from submitRejectTimesheet() if (TempData["emailSentFlag"] != null) { ViewBag.emailSentFlag = true; ViewBag.messageRecipient = TempData["recipient"]; } string division = getUserDivision(); IEnumerable<TARSUser> employees = getDivisionEmployeeObjList(division, department); ViewBag.division = division; ViewBag.departmentList = getDepartmentSelectList(division); ViewBag.refDate = refDate; ViewBag.refSunday = refDate.StartOfWeek(DayOfWeek.Sunday); ViewBag.refPayPeriod = getPayPeriod(refDate); return View(employees); } else { return View("error"); } }
public void checkForTimesheet(string userName, DateTime tsDate) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Timesheet resulttimesheet = new Timesheet(); DateTime startDay = tsDate.StartOfWeek(DayOfWeek.Sunday); //Check if there is a timesheet for the week that corresponds to newhours.timestamp var searchTs = from m in TimesheetDB.TimesheetList where (m.worker.CompareTo(userName) == 0) where m.periodStart <= tsDate where m.periodEnd >= tsDate select m; foreach (var item in searchTs) { resulttimesheet = item; } //if there isn't a timesheet for the pay period, then create one //If there is a timesheet for the current pay period, don't do anything if (resulttimesheet.periodStart.CompareTo(startDay) != 0) { createTimesheet(userName, startDay); return; } return; } else { return; } }
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 Index() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth ) { return RedirectToAction("viewTimesheet", new { tsDate = DateTime.Now }); } else { return View("notLoggedOn"); } }
// // Returns manager Index view // Overridden from User/Index, which was virtual. public override ActionResult Index() { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { return View(); } else { return View("error"); } }
// /* Creates an empty Work Effort object and sends it to the view, along with a * selection list of divisions. */ public virtual ActionResult addWorkEffort() { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { ViewBag.divisionList = getDivisionSelectList(); return View(new WorkEffort()); } else { return View("error"); } }
public virtual ActionResult addPCA() { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { ViewBag.divisionList = getDivisionSelectList(); return View(new PcaCode()); } else { return View("error"); } }
// /* Retrieves Timesheet object with specified ID and changes "submitted" and * "approved" statuses to FALSE. Also sends a notification email to the employee */ public virtual ActionResult submitRejectTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = false; ts.approved = false; //save changes to the database TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); //send an email to employee to notify them string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has been rejected by a manager. " + "Please fix it and re-submit as soon as possible.<br /><br />Thanks!"; SendEmail(ts.worker, "Rejected Timesheet", body); TempData["emailSentFlag"] = true; TempData["recipient"] = ts.worker; TempData["emailError"] = TempData["emailError"]; return RedirectToAction("userManagement", new { refDate=DateTime.Now }); } else { return View("error"); } } else { return View("error"); } }
// /* Retrieves Timesheet object with specified ID and changes "submitted" and * "approved" statuses to TRUE. Also sends a notification email to the employee */ public virtual ActionResult submitApproveTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = true; ts.approved = true; TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; //save changes to the database TimesheetDB.SaveChanges(); //send an email to employee to notify of timesheet approval string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has been approved by a manager."; SendEmail(ts.worker, "Timesheet Approved", body); return RedirectToAction("userManagement", new { refDate = DateTime.Now }); } else { return View("error"); } } else { return View("error"); } }
public virtual ActionResult approveTimesheet(int userKeyID, DateTime tsDate) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { TARSUser employee = TARSUserDB.TARSUserList.Find(userKeyID); Timesheet timesheet = getTimesheet(employee.userName, tsDate); if (timesheet == null) { createTimesheet(employee.userName, DateTime.Now); ViewBag.timesheet = getTimesheet(employee.userName, DateTime.Now); } else { ViewBag.timesheet = timesheet; } var hoursList = from m in HoursDB.HoursList where (m.creator.CompareTo(employee.userName) == 0) where m.timestamp >= timesheet.periodStart where m.timestamp <= timesheet.periodEnd select m; TempData["hoursList"] = hoursList; //convert hoursList into a format that the view can use List<TimesheetRow> tsRows = convertHoursForTimesheetView(); ViewBag.workEffortList = getVisibleWorkEffortSelectList(getUserDivision()); ViewBag.refDate = tsDate; ViewBag.userKeyID = userKeyID; return View(tsRows); } else { return View("error"); } }
public virtual ActionResult viewPCA_WE(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { PCA_WE pca_we = PCA_WEDB.PCA_WEList.Find(id); return View(pca_we); } else { return View("error"); } }
public virtual ActionResult searchPCA_WE() { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { return View(PCA_WEDB.PCA_WEList.ToList()); } else { return View("error"); } }
// /* Retrieves Work Effort object with specified ID, and changes "hidden" to FALSE * so users can log hours to it on their timesheet */ public virtual ActionResult unHideWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { WorkEffort we = WorkEffortDB.WorkEffortList.Find(id); we.hidden = false; WorkEffortDB.Entry(we).State = System.Data.EntityState.Modified; WorkEffortDB.SaveChanges(); return RedirectToAction("WeManagement"); } else { return View("error"); } }
// /* Returns title that is shown when hovering over a timesheet day cell in * viewTimesheet view. If the timesheet is submitted or locked, then the title * will reflect that (unless user is an Admin). Otherwise, it will show * "Add/Edit Hours" */ public virtual string getTimesheetDayCellTitle(Timesheet ts) { string title = ""; Authentication auth = new Authentication(); if ( (ts.approved == true) || (ts.locked == true) ) { if (auth.isAdmin(this)) { title = "Admin: Add/Edit Hours"; } else { title = getTimesheetStatus(ts.worker, ts.periodStart); } } else { title = "Add/Edit Hours"; } return title; }
[HttpPost, ActionName("deleteWorkEffort")] //This action MUST match the above delete function. public virtual ActionResult confirmedDeleteWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { //make sure that there aren't any hours billed to the work effort if (checkWeForBilledHours(id) == true) { TempData["failedDelete"] = true; return RedirectToAction("weManagement"); } else { WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); //change the active status to FALSE for all PCA_WE entries for the work effort deactivateAllPcaWeForWorkEffort(id); //delete the work effort WorkEffortDB.WorkEffortList.Remove(workeffort); WorkEffortDB.SaveChanges(); return RedirectToAction("weManagement"); } } else { return View("error"); } }
// /* Retrieves list of employee that work for specified division and department, and returns * the names as a selection list. If division is null, it returns all employee names */ public virtual List<SelectListItem> getDivisionEmployeeSelectList(string division = null) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { List<SelectListItem> employeeNames = new List<SelectListItem>(); var searchUsers = from m in TARSUserDB.TARSUserList select m; if ((division != null) && (division.CompareTo("All") != 0)) { searchUsers = from m in searchUsers where (m.company.CompareTo(division) == 0) select m; } employeeNames.Add(new SelectListItem { Text = "All", Value = "All" }); foreach (var item in searchUsers) { employeeNames.Add(new SelectListItem { Text = item.userName, Value = item.userName }); } return employeeNames; } else { return null; } }
// /* Retrieves the Work Effort object with specified ID and returns the description of * as a string. If the Work Effort has been deactivated, then a message is returned * that shows the ID and states that the Work Effort no longer exists. */ public virtual string getWeDescription(int id) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { string weDescription = ""; var searchWorkEfforts = from w in WorkEffortDB.WorkEffortList where w.ID == id select w; foreach (var item in searchWorkEfforts) { weDescription = item.description; } //If the Work Effort no longer exists, return the id and a message if (weDescription.Length == 0) { weDescription = "(Work Effort no longer exists. The unique ID was " + id + ")"; } return weDescription; } else { return null; } }
public ActionResult viewHistory(DateTime start, DateTime end, string division = null, string un = null, string dbtable = null) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { IEnumerable<History> searchHist = from h in HistoryDB.HistoryList where h.timestamp >= start where h.timestamp <= end select h; if ( (division != null)&&(division.CompareTo("All") != 0) ) { IEnumerable<SelectListItem> names = getDivisionEmployeeSelectList(division); List<History> tmpList = new List<History>(); foreach (var item in names) { var name = from h in searchHist where (h.username.CompareTo(item.Value) == 0) select h; foreach (var nameObj in name) { tmpList.Add(nameObj); } } searchHist = (IEnumerable<History>)tmpList; } if ((un != null) && (un.CompareTo("All") != 0)) { searchHist = from h in searchHist where (h.username.CompareTo(un) == 0) select h; } if ( (dbtable != null)&&(dbtable.CompareTo("All") != 0) ) { searchHist = from h in searchHist where (h.dbtable.CompareTo(dbtable) == 0) select h; } ViewBag.start = start.ToShortDateString(); ViewBag.end = end.ToShortDateString(); ViewBag.divisionList = getDivisionSelectList(); ViewBag.employeeList = getDivisionEmployeeSelectList(division); ViewBag.dbtableList = getDbTableSelectList(); return View(searchHist.ToList()); } else { return View("error"); } }
public virtual ActionResult weManagement() { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { var workEffortList = WorkEffortDB.WorkEffortList.ToList(); //create a list of lists for pca codes //(each work effort will have a list of PCA codes) ViewBag.pcaListOfLists = new List<List<SelectListItem>>(); foreach (var item in workEffortList) { ViewBag.pcaListOfLists.Add(getWePcaCodesSelectList(item)); } //check if an "unable to hide Work Effort error should be displayed" if (TempData["failedHide"] != null) { ViewBag.failedHide = true; } //check if an "unable to delete Work Effort error should be displayed" if (TempData["failedDelete"] != null) { ViewBag.failedDelete = true; } return View(workEffortList); } else { return View("error"); } }
public ActionResult viewHistory(DateTime start, DateTime end) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { var searchHist = from h in HistoryDB.HistoryList where h.timestamp >= start where h.timestamp <= end select h; ViewBag.start = start.ToShortDateString(); ViewBag.end = end.ToShortDateString(); ViewBag.divisionList = getDivisionSelectList(); ViewBag.employeeList = getDivisionEmployeeSelectList(); ViewBag.dbtableList = getDbTableSelectList(); return View(searchHist.ToList()); } else { return View("error"); } }
public virtual ActionResult managerEditHours(int hrsID, int tsID) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { Hours hours = HoursDB.HoursList.Find(hrsID); WorkEffort we = WorkEffortDB.WorkEffortList.Find(hours.workEffortID); Timesheet timesheet = TimesheetDB.TimesheetList.Find(tsID); ViewBag.timesheetLockedFlag = timesheet.locked; Authentication newAuth = new Authentication(); bool adminFlag = newAuth.isAdmin(this); ViewBag.adminFlag = adminFlag; ViewBag.workEffort = we; ViewBag.timeCodeList = getTimeCodeList(); return View(hours); } else { return View("error"); } }
public virtual ActionResult managerEditHours(Hours tmpHours) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { if (ModelState.IsValid) { HoursDB.Entry(tmpHours).State = EntityState.Modified; HoursDB.SaveChanges(); } int userKeyID = getUserKeyID(tmpHours.creator); return RedirectToAction("approveTimesheet", new { userKeyID = userKeyID, tsDate = tmpHours.timestamp }); } else { return View("error"); } }
// // Retrieves the department that the logged in user works for and returns it as a string public virtual string getUserDepartment() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { string department = ""; var searchUsers = from m in TARSUserDB.TARSUserList where (m.userName.CompareTo(User.Identity.Name) == 0) select m; foreach (var item in searchUsers) { department = item.department; } return department; } else { return null; } }
// /* Retrieves list of employees that work for specified division and department, and returns * them as a list. If division is null, it returns a list of all employees */ public virtual List<TARSUser> getDivisionEmployeeObjList(string division = null, string department = null) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { List<TARSUser> divEmployees = new List<TARSUser>(); var searchUsers = from m in TARSUserDB.TARSUserList select m; if ( (division != null)&&(division.CompareTo("All") != 0) ) { if ( (department != null)&&(department.CompareTo("All") != 0) ) { searchUsers = from m in searchUsers where (m.company.CompareTo(division) == 0) where (m.department.CompareTo(department) == 0) select m; } else { searchUsers = from m in searchUsers where (m.company.CompareTo(division) == 0) select m; } } foreach (var item in searchUsers) { divEmployees.Add(item); } return divEmployees; } else { return null; } }
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"); } }
// // Returns all database tables as a selection list public virtual List<SelectListItem> getDbTableSelectList() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { List<SelectListItem> tableSelectList = new List<SelectListItem>(); var tableList = new List<string>(); tableList.Add("Timesheets"); tableList.Add("Hours"); tableList.Add("WorkEfforts"); tableList.Add("PcaCodes"); tableList.Add("PCA_WE"); tableList.Add("TARSUsers"); tableList.Add("Holidays"); tableSelectList.Add(new SelectListItem { Text = "All", Value = "All" }); foreach (var item in tableList) { tableSelectList.Add(new SelectListItem { Text = item, Value = item }); } return tableSelectList; } else { return null; } }
public virtual ActionResult deleteWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isManager(this) || Authentication.DEBUG_bypassAuth) { WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); ViewBag.pcaList = getWePcaCodesSelectList(workeffort); return View(workeffort); } else { return View("error"); } }