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 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; } }
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 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; } }
// // 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 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; } }
// // Retrieves the IDHW Divisions and returns as a list of strings public virtual List<SelectListItem> getDivisionSelectList() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { List<SelectListItem> divList = new List<SelectListItem>(); var searchDivisions = from m in DivisionsDB.DivisionsList select m; divList.Add(new SelectListItem { Text = "All", Value = "All" }); foreach (var item in searchDivisions) { divList.Add(new SelectListItem { Text = item.divName, Value = item.divName }); } return divList; } else { return null; } }
// /* Retrieves timesheet object with specified ID and changes submitted status to TRUE. * It then saves the change and redirects to viewTimesheet() */ public virtual ActionResult submitTimesheet(int id) { if (id >= 0) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Timesheet ts = new Timesheet(); ts = TimesheetDB.TimesheetList.Find(id); ts.submitted = true; //save changes to the database TimesheetDB.Entry(ts).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); //send an email to employee to confirm timesheet submittal string body = "Your IDHW timesheet for the pay period of " + ts.periodStart + " - " + ts.periodEnd + " has successfully been submitted."; SendEmail(ts.worker, "Timesheet Submitted", body); return RedirectToAction("viewTimesheet", new { tsDate = ts.periodStart.AddDays(2) }); } else { return View("notLoggedOn"); } } else { return View("error"); } }
// /* Retrieves a list of the current user's hours for the time period that tsDate falls within. * The list is saved in TempData[], then convertHoursForTimesheetView() is called. * convertHoursForTimesheetView() returns a list of TimesheetRow objects, which is sent to the view. */ public virtual ActionResult viewTimesheet(DateTime tsDate) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { string userName = User.Identity.Name; checkForTimesheet(userName, tsDate); //creates timesheet if it doesn't exist Timesheet timesheet = getTimesheet(userName, tsDate); Timesheet prevTimesheet = getTimesheet(userName, tsDate.AddDays(-7)); ViewBag.timesheet = timesheet; //The View won't provide a link to previous timesheet unless it exists if (prevTimesheet == null) { ViewBag.noPreviousTimesheet = true; } //select all hours from the timesheet var hoursList = from m in HoursDB.HoursList where (m.creator.CompareTo(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()); return View(tsRows); } else { return View("notLoggedOn"); } }
public virtual ActionResult copyTimesheet() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { string userName = User.Identity.Name; Timesheet previousTimesheet = new Timesheet(); DateTime dayFromPrevPeriod = DateTime.Now; dayFromPrevPeriod = dayFromPrevPeriod.AddDays(-7); List<Hours> resultHours = new List<Hours>(); //Select the timesheet from the previous pay period if it exists var searchTs = from m in TimesheetDB.TimesheetList where (m.worker.CompareTo(userName) == 0) where m.periodStart <= dayFromPrevPeriod where m.periodEnd >= dayFromPrevPeriod select m; foreach (var item in searchTs) { previousTimesheet = item; } //Iterate through each entry from previous week and duplicate it for this week var searchHours = from m in HoursDB.HoursList where (m.creator.CompareTo(userName) == 0) where m.timestamp >= previousTimesheet.periodStart where m.timestamp <= previousTimesheet.periodEnd select m; foreach (var item in searchHours) { resultHours.Add(item); } foreach (var copiedHours in resultHours) { copiedHours.hours = 0; copiedHours.timestamp = DateTime.Now.StartOfWeek(DayOfWeek.Sunday); addHours(copiedHours); } return RedirectToAction("viewTimesheet", new { tsDate = DateTime.Now }); } else { return View("notLoggedOn"); } }
public virtual ActionResult deleteHours(int id) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Hours hours = HoursDB.HoursList.Find(id); HoursDB.Entry(hours).State = EntityState.Deleted; HoursDB.SaveChanges(); return RedirectToAction("viewTimesheet", new { tsDate = hours.timestamp }); } else { return View("notLoggedOn"); } }
public virtual bool editHours(int id, int numHours) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Hours tmpHours = HoursDB.HoursList.Find(id); tmpHours.hours = numHours; //save changes to database HoursDB.Entry(tmpHours).State = EntityState.Modified; HoursDB.SaveChanges(); return true; } else { return false; } }
public virtual ActionResult viewWorkEffort(int id) { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Authentication newAuth = new Authentication(); if (newAuth.isManager(this)) { ViewBag.managerFlag = true; } WorkEffort workeffort = WorkEffortDB.WorkEffortList.Find(id); if (workeffort == null) { return HttpNotFound(); } ViewBag.pcaList = getWePcaCodesSelectList(workeffort); ViewBag.WorkEffortID = workeffort.ID; return View(workeffort); } else { return View("notLoggedOn"); } }
public virtual ActionResult searchWorkEffort() { Authentication auth = new Authentication(); if (auth.isUser(this) || Authentication.DEBUG_bypassAuth) { Authentication auth2 = new Authentication(); if (auth2.isManager(this)) { ViewBag.managerFlag = true; } 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)); } return View(workEffortList); } else { return View("notLoggedOn"); } }