public async Task <AllLoginLogReadListResponse> GetAllUserLoginLogs(AllLoginLogReadListRequest request) { var response = new AllLoginLogReadListResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (!currentUser.IsSuperAdmin) { response.SetInvalid(); return(response); } Expression <Func <UserLoginLog, object> > orderByColumn = x => x.Id; Expression <Func <UserLoginLog, bool> > filter = null; if (request.SearchTerm.IsNotEmpty()) { filter = x => x.Name.Contains(request.SearchTerm); } 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 async Task <IActionResult> UserLoginLogListData(int skip, int take) { var request = new AllLoginLogReadListRequest(CurrentUser.Id); SetPaging(skip, take, request); var response = await _adminService.GetAllUserLoginLogs(request); if (response.Status.IsNotSuccess) { return(NotFound()); } var result = new DataResult(); result.AddHeaders("organization", "user", "ip", "country", "city", "browser", "browser_version", "platform", "platform_version", "created_at"); for (var i = 0; i < response.Items.Count; i++) { var item = response.Items[i]; var stringBuilder = new StringBuilder(); stringBuilder.Append($"{item.Uid}{DataResult.SEPARATOR}"); stringBuilder.Append($"{result.PrepareLink($"/Organization/Detail/{item.OrganizationUid}", item.OrganizationName)}{DataResult.SEPARATOR}"); stringBuilder.Append($"{result.PrepareLink($"/User/Detail/{item.Uid}", item.UserName)}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.Ip}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.Country}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.City}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.Browser}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.BrowserVersion}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.Platform}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.PlatformVersion}{DataResult.SEPARATOR}"); stringBuilder.Append($"{GetDateTimeAsString(item.CreatedAt)}{DataResult.SEPARATOR}"); result.Data.Add(stringBuilder.ToString()); } result.PagingInfo = response.PagingInfo; result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS; return(Json(result)); }
public static AllLoginLogReadListRequest GetAllLoginLogReadListRequest() { var request = new AllLoginLogReadListRequest(CurrentUserId); return(request); }