Esempio n. 1
0
 public GetOnlineUsersReportResultDto Execute(GetOnlineUsersReportDto dto)
 {
     return(new GetOnlineUsersReportResultDto
     {
         Status = true,
         Object = unit.User.GetOnlineReport(dto)
     });
 }
Esempio n. 2
0
        public OnlineUsers GetOnlineReport(GetOnlineUsersReportDto dto)
        {
            var             week  = DateTime.Now.SubDays(7);
            var             users = ctx.Users.Include(p => p.WorkTime).ToList();
            List <WorkTime> group = users.Where(p =>
            {
                return(p.WorkTime.Any(q => q.IsInput && q.CreatedAt.SubDays(0) > week));
            }).ToList().SelectMany(p => p.WorkTime.Where(q => q.IsInput)).OrderByDescending(p => p.CreatedAt).ToList();


            var onlineCount = users.Where(p =>
            {
                var result = p.WorkTime.OrderByDescending(q => q.CreatedAt).FirstOrDefault()?.IsInput;
                return(result.HasValue);
            }).Count();

            return(new OnlineUsers
            {
                TotalCount = onlineCount,
                LastWeek = group.GroupBy(p => p.CreatedAt.DayName()).Select(t => new OnlineUserPerDay {
                    DayName = t.Key, Count = t.ToList().Count
                }).ToList()
            });
        }