/// <summary> /// Gets the last weeks worth of shifts for the current user. /// </summary> /// <param name="sessionID">The sessionID of the current session</param> /// <returns></returns> public List<ShiftData> GetLastWeeksShifts(string sessionID) { WorkerShiftsTableAdapter wta = new WorkerShiftsTableAdapter(); var lastWeekShifts = wta.GetDataByEmployeeID(Auth.getEmployeeID(sessionID), DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0))); List<ShiftData> re = new List<ShiftData>(); foreach (var shift in lastWeekShifts) { ShiftData sd = new ShiftData(); sd.EmployeeID = shift.EmployeeID; if (shift.IsEndTimeNull()) sd.EndTime = null; else sd.EndTime = shift.EndTime; sd.StartTime = shift.StartTime; sd.Role = shift.Role; sd.ShiftID = shift.ID; if (sd.EndTime != null) { sd.HoursWorked = (decimal)sd.EndTime.Value.Subtract(sd.StartTime).TotalHours; } else { sd.HoursWorked = 0; } re.Add(sd); } return re; }
/// <summary> /// Determines whether this instance can stamp out the current user. /// </summary> /// <param name="sessionID">The sessionID of the current session</param> /// <returns> /// <c>true</c> if this instance can stamp out the current user; otherwise, <c>false</c>. /// </returns> public bool CanStampOut(string sessionID) { WorkerShiftsTableAdapter wta = new WorkerShiftsTableAdapter(); var lastStartTime = wta.GetDataByEmployeeID(Auth.getEmployeeID(sessionID), DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0))).FirstOrDefault(); if (lastStartTime == null || !lastStartTime.IsEndTimeNull()) { return false; } return true; }
/// <summary> /// Ends the shift of the given user if they are in a shift. /// </summary> /// <param name="sessionID">The sessionID of the current session</param> /// <returns> /// Returns true if the user's shift could be ended, else returns false /// </returns> public bool StampShiftEnd(string sessionID) { WorkerShiftsTableAdapter wta = new WorkerShiftsTableAdapter(); var lastStartTime = wta.GetDataByEmployeeID(Auth.getEmployeeID(sessionID), DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0))).FirstOrDefault(); EmployeeStatusTableAdapter est = new EmployeeStatusTableAdapter(); est.UpdateStatus(false, "", Auth.getEmployeeID(sessionID)); if (lastStartTime == null || !lastStartTime.IsEndTimeNull()) { return false; } else { lastStartTime.EndTime = DateTime.Now; wta.Update(lastStartTime); return true; } }