/// <summary> /// Validate timesheet hours - should not be greater than 8 per day /// </summary> /// <param name="list"></param> /// <param name="timesheetDate"></param> /// <param name="enteredHours"></param> /// <param name="timesheetId"></param> /// <param name="objRepository"></param> /// <returns></returns> public static bool ValidHours(SPList list, DateTime timesheetDate, double enteredHours, int timesheetId, TimesheetRespository objRepository) { bool isValid = true; SPListItemCollection itemColl = objRepository.GetTimesheetsByUserAndDate(list, SPContext.Current.Web.CurrentUser.ID, timesheetDate); if (itemColl != null && itemColl.Count > 0) { double totalHours = 0; foreach (SPListItem item in itemColl) { if (!item.ID.Equals(timesheetId)) { totalHours += Convert.ToDouble(item["Hours"]); } } if (totalHours >= 8) { isValid = false; } else { totalHours += enteredHours; if (totalHours > 8) { isValid = false; } } } return(isValid); }