示例#1
0
        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());
        }
示例#2
0
        public static CustomTimeTrack GetUserTimeTrackHistoryForSpecifiedPeriod(string userName, DateTime startDate, DateTime endDate)
        {
            var weekEndDateToSearchInDatabase = endDate.AddDays(1);

            var customTimeTrack = new CustomTimeTrack
            {
                CustomStartDate = startDate.Date,
                CustomEndDate   = endDate.Date,
                UserName        = userName,
                DailyTimeTracks = new List <DailyTimeTrack>()
            };

            using (var dbContext = new TimeTrackingEntities())
            {
                var currentUser = dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName));

                customTimeTrack.EmployeeName = currentUser.FirstName + " " + currentUser.LastName;

                var userClockInOutTimings = (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 (userClockInOutTimings.Any())
                {
                    var currentDay = startDate.Date;

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

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


                        customTimeTrack.DailyTimeTracks.Add(dailyTimeTrack);
                        customTimeTrack.DailyTimeTracks = customTimeTrack.DailyTimeTracks.OrderByDescending(c => c.StampDate).ToList();
                        currentDay = currentDay.AddDays(1);
                    }
                }
            }

            return(customTimeTrack);
        }
示例#3
0
        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 TimeTrackingEntities())
            {
                var currentUser =
                    dbContext.ExtendedUserProfiles.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();

                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);
        }
示例#4
0
        public static DailyTimeTrack GetCurrentDayClockInOutTime(string userName)
        {
            var startDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]).Date;
            var endDate   = startDate.AddDays(1);

            using (var dbContext = new TimeTrackingEntities())
            {
                var currentUser =
                    dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName));

                var userClockInOutTimeList = (from utsh in dbContext.UserTimeTrackHistories
                                              where utsh.IsDeleted == false &&
                                              utsh.UserName.ToLower().Equals(userName.ToLower()) &&
                                              (utsh.StampDate >= startDate && utsh.StampDate < endDate) &&
                                              utsh.ClockInTime.Length > 0
                                              select utsh).ToList();

                if (userClockInOutTimeList.Any())
                {
                    var userTimeStampHistory = userClockInOutTimeList.FirstOrDefault();
                    if (userTimeStampHistory != null)
                    {
                        var dailyTimeTrack = new DailyTimeTrack(userTimeStampHistory.StampDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0)
                        {
                            TimeTrackList =
                                GetTimeTrackList(userClockInOutTimeList, userTimeStampHistory.StampDate).
                                OrderByDescending(c => c.ClockInTime).ThenByDescending(
                                    d => d.ClockOutTime).ToList()
                        };

                        dailyTimeTrack.SubmitButtonText = dailyTimeTrack.TimeTrackList.Any(c => c.ClockOutTime == null) ? WebConfigurationManager.AppSettings["ClockOutText"] : WebConfigurationManager.AppSettings["ClockInText"];
                        return(dailyTimeTrack);
                    }
                }
                return(new DailyTimeTrack());
            }
        }