public async Task <JournalReadListResponse> GetJournalsOfUser(UserJournalReadListRequest request) { var response = new JournalReadListResponse(); var user = _cacheManager.GetCachedUser(request.UserUid); if (user == null) { response.SetInvalidBecauseNotFound("user"); return(response); } Expression <Func <Journal, bool> > filter = x => x.UserId == user.Id; var entities = await _journalRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, x => x.Id, request.PagingInfo.IsAscending); if (entities != null) { for (var i = 0; i < entities.Count; i++) { var entity = entities[i]; var dto = _journalFactory.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 _journalRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }
public async Task <IActionResult> JournalListData(Guid id, int skip, int take) { var userUid = id; if (userUid.IsEmptyGuid()) { userUid = CurrentUser.Uid; } var request = new UserJournalReadListRequest(CurrentUser.Id, userUid); SetPaging(skip, take, request); var response = await JournalService.GetJournalsOfUser(request); if (response.Status.IsNotSuccess) { return(NotFound()); } var result = new DataResult(); result.AddHeaders("message", "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($"{item.Message}{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 UserJournalReadListRequest GetUserJournalReadListRequest() { var request = new UserJournalReadListRequest(CurrentUserId, OrganizationOneUserOneUid); return(request); }