public static DailyTimeTrack GetDailyClockInOutTimeByDate(string userName, DateTime startDate, DateTime endDate)
{
var weekEndDateToSearchInDatabase = endDate.AddDays(1);
using (var dbContext = new TimeTrackingEntities())
{
var currentUser =
dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName));
var userTimeTrackHistoryForRequestedDay = (from utsh in dbContext.UserTimeTrackHistories
where utsh.IsDeleted == false &&
utsh.UserName.ToLower().Equals(userName.ToLower()) &&
(utsh.StampDate >= startDate && utsh.StampDate < weekEndDateToSearchInDatabase) &&
utsh.ClockInTime.Length > 0
select utsh).ToList();
if (userTimeTrackHistoryForRequestedDay.Any())
{
var dailyTimeTrack = new DailyTimeTrack(startDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0)
{
StampDate = startDate,
TimeTrackList =
GetTimeTrackList(userTimeTrackHistoryForRequestedDay, startDate).
OrderByDescending(c => c.TimeTrackId).ThenByDescending(
d => d.ClockInTime).ToList()
};
return dailyTimeTrack;
}
}
return new DailyTimeTrack();
}