示例#1
0
        public async Task <IEnumerable <AttendanceTrendModel> > GetAttendanceStatisticsByClient(int clientId, int userId, int?placeId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanViewClientAdminDashboard))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var data = await _dashboardRepository.GetAttendanceStatisticsByClient(clientId, placeId);

            var totalPresentEmployees = data.Count();
            var todayDate             = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0);

            var list = new List <AttendanceTrendModel>();

            for (int i = 7; i > 0; i--)
            {
                var startDate = todayDate.AddDays(-i);
                var endDate   = todayDate.AddDays(-(i - 1));

                var dataCount = data.Where(a => a.AttendanceDate.Value >= startDate && a.AttendanceDate.Value < endDate).Count();

                var model = new AttendanceTrendModel();
                model.AttendanceTime = startDate.ToString("dd MMM");
                model.Attendance     = dataCount;
                list.Add(model);
            }

            return(list);
        }
示例#2
0
        public async Task <IEnumerable <AttendanceTrendModel> > GetInOfficeEmployeesByClient(int clientId, int userId, int?placeId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanViewClientAdminDashboard))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var data = await _dashboardRepository.GetInOfficeEmployeesByClient(clientId, placeId);

            var totalPresentEmployees = data.Count();

            var shifts = await _shiftRepository.QueryAsync(clientId);

            var shiftTime = DateTime.UtcNow.Date;

            if (shifts.Count() > 0)
            {
                var shiftDay = shifts.OrderBy(s => s.Id).FirstOrDefault().ShiftDetails.Where(sd => sd.DayOfWeek == (int)DateTime.Now.DayOfWeek).FirstOrDefault();
                if (shiftDay != null && shiftDay.IsWorkingDay)
                {
                    shiftTime = shiftDay.StartTime.Value;
                }
            }

            var currentTime = DateTime.UtcNow;

            shiftTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, shiftTime.Hour, shiftTime.Minute, shiftTime.Second);

            var list = new List <AttendanceTrendModel>();

            var tracks = data.SelectMany(e => e.Tracks).Where(t => t.IsIn.Value).ToList();

            while (shiftTime < currentTime)
            {
                var dataCount = tracks.Where(t => t.FromTime.Value <= shiftTime && t.ToTime.Value > shiftTime).Count();

                var model = new AttendanceTrendModel();
                model.AttendanceTimeDt = shiftTime;
                model.AttendanceTime   = shiftTime.ToString("HH:mm");
                model.Attendance       = dataCount;
                list.Add(model);

                shiftTime = shiftTime.AddMinutes(1);
            }

            return(list);
        }