public WeeklyTimeTrackWeekListViewModel()
 {
     WeeklyTimeTrack=new WeeklyTimeTrack();
     WeekList = new List<SelectListItem>();
 }
 public WeeklyTimeTrackWeekListViewModel(WeeklyTimeTrack weeklyTimeTrack, IEnumerable<SelectListItem> weekList)
 {
     WeeklyTimeTrack = weeklyTimeTrack;
     WeekList = weekList;
 }
        public static WeeklyTimeTrack GetWeeklyClockInOutTimeByDate(string userName, DateTime startDate, DateTime endDate)
        {
            var weekEndDateToSearchInDatabase = endDate.AddDays(1);

            var weeklyTimeTrack = new WeeklyTimeTrack
            {
                WeekStartDate = startDate.Date,
                WeekEndDate = endDate.Date,
                DailyTimeTracks = new List<DailyTimeTrack>()
            };
            using (var dbContext = new SchTimeTrackingEntities())
            {
                var currentUser =
                    dbContext.UserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName));
                var userWeeklyClockInOutTimings = (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();
                weeklyTimeTrack.RoleName = (currentUser.RoleId == 3? "User": "******");
                if (userWeeklyClockInOutTimings.Any())
                {
                    var weekDay = startDate.Date;

                    while (weekDay.Date <= endDate.Date)
                    {
                        var dailyUserStampList =
                            userWeeklyClockInOutTimings.Where(
                                daily =>
                                daily.StampDate >= weekDay &&
                                daily.StampDate < weekDay.AddDays(1)).ToList();

                        var dailyTimeTrack = new DailyTimeTrack(startDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0)
                        {
                            StampDate = weekDay,
                            TimeTrackList =
                                GetTimeTrackList(dailyUserStampList, weekDay).
                                    OrderByDescending(c => c.ClockInTime).ThenByDescending(
                                        d => d.ClockOutTime).ToList()
                        };

                        weeklyTimeTrack.DailyTimeTracks.Add(dailyTimeTrack);
                        weeklyTimeTrack.DailyTimeTracks = weeklyTimeTrack.DailyTimeTracks.OrderByDescending(c => c.StampDate).ToList();
                        weekDay = weekDay.AddDays(1);
                    }
                }
            }
            return weeklyTimeTrack;
        }