public async Task <UserLoginLogReadListResponse> GetUserLoginLogs(UserLoginLogReadListRequest request) { var response = new UserLoginLogReadListResponse(); var user = _cacheManager.GetCachedUser(request.UserUid); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (user.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } Expression <Func <UserLoginLog, bool> > filter = x => x.OrganizationId == user.OrganizationId && x.UserId == user.Id; Expression <Func <UserLoginLog, object> > orderByColumn = x => x.Id; if (request.SearchTerm.IsNotEmpty()) { filter = x => x.Name.Contains(request.SearchTerm) && x.OrganizationId == user.OrganizationId && x.UserId == user.Id; } List <UserLoginLog> entities; if (request.PagingInfo.Skip < 1) { entities = await _userLoginLogRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending); } else { entities = await _userLoginLogRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending); } if (entities != null) { for (var i = 0; i < entities.Count; i++) { var entity = entities[i]; var dto = _userLoginLogFactory.CreateDtoFromEntity(entity); response.Items.Add(dto); } } response.PagingInfo.Skip = request.PagingInfo.Skip; response.PagingInfo.Take = request.PagingInfo.Take; response.PagingInfo.LastUid = request.PagingInfo.LastUid; response.PagingInfo.IsAscending = request.PagingInfo.IsAscending; response.PagingInfo.TotalItemCount = await _userLoginLogRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }
public static UserLoginLogReadListRequest GetUserLoginLogReadListRequest() { var request = new UserLoginLogReadListRequest(CurrentUserId, UidOne); return(request); }