public static SearchResults <ApiMemberAccessLogItem> Search(MemberAccessLogFilters filters, DatabaseContext databaseContext, IMemberService memberService, IUserService userService)
        {
            List <ApiMemberAccessLogItem> items = MemberAccessLogItem.GetAll(databaseContext, filters)
                                                  .Select(i => new ApiMemberAccessLogItem(i, memberService, userService))
                                                  .ToList();

            IEnumerable <ApiMemberAccessLogItem> page = items.Skip((filters.Page - 1) * filters.PageSize).Take(filters.PageSize);

            return(new SearchResults <ApiMemberAccessLogItem>(page, items.Count, filters.Page, filters.PageSize));
        }
Example #2
0
        public MemberAccessLogViewModel(IMemberService memberService, IUserService userService, DatabaseContext databaseContext, Guid?memberId = null)
        {
            Filters = new MemberAccessLogFilters
            {
                From     = DateTime.Today.AddMonths(-1),
                To       = DateTime.Today,
                Page     = 1,
                PageSize = 10
            };

            if (memberId.HasValue)
            {
                // Only show this member's activity
                Filters.MemberId = memberId;
            }
            else
            {
                // All members
                Members = memberService
                          .GetAll(0, int.MaxValue, out int _)
                          .OrderBy(m => m.Name)
                          .Select(m => new ApiMember
                {
                    Id   = m.Id,
                    Name = m.Name,
                    Guid = m.Key
                });
            }

            SearchResults = ApiMemberAccessLogItem.Search(Filters, databaseContext, memberService, userService);
            Users         = userService
                            .GetAll(0, int.MaxValue, out int _)
                            .OrderBy(u => u.Name)
                            .Select(u => new ApiUser
            {
                Id   = u.Id,
                Name = u.Name
            });

            Actions = Enums.Values <MemberAccessAction>()
                      .ToDictionary(aa => (int)aa, aa => aa.ToString())
                      .ToList();
        }