// /* Retrieves the Timesheet object for the specified employee and reference date, * changes "locked", "approved", and "submitted" fields to FALSE, and saves the * changes in the database. */ public void adminUnlockTimesheet(string username, DateTime refDate) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { Timesheet tmpTs = new Timesheet(); var searchTs = from t in TimesheetDB.TimesheetList where (t.worker.CompareTo(username) == 0) where t.periodStart <= refDate where t.periodEnd >= refDate select t; foreach (var item in searchTs) { tmpTs = item; tmpTs.locked = false; tmpTs.approved = false; tmpTs.submitted = false; } //save changes in database TimesheetDB.Entry(tmpTs).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); } return; }
// /* Locks all timesheets that ended more than two days ago. If there was a holiday during * the previous pay period, lockDate will have an extra day added to it. * (note: called from /ScheduledJobs/TarsScheduledJobs every Tuesday and Wednesday at 12am) */ public void lockTimesheets() { DateTime refDate = DateTime.Now.Date; DateTime lockDate = DateTime.Now.Date; Timesheet tmpTimesheet = new Timesheet(); List <Timesheet> tsList = new List <Timesheet>(); // If there was a holiday, allow three days after periodEnd before locking if (isHolidayWeek(refDate.AddDays(-7))) { lockDate = refDate.AddDays(-1); } else { lockDate = refDate.AddDays(-2); } var searchTimesheets = from t in TimesheetDB.TimesheetList where t.locked != true where t.periodEnd < lockDate select t; foreach (var item in searchTimesheets) { tmpTimesheet = item; tmpTimesheet.locked = true; tsList.Add(tmpTimesheet); } foreach (var item in tsList) { //save changes in database TimesheetDB.Entry(item).State = System.Data.EntityState.Modified; TimesheetDB.SaveChanges(); } }
// /* 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")); } }
// /* 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")); } }