public static ProjectReadListRequest GetProjectReadListRequest() { var organization = GetOrganizationOne(); var request = new ProjectReadListRequest(CurrentUserId, organization.Uid); return(request); }
public async Task <ProjectReadListResponse> GetProjects(ProjectReadListRequest request) { var response = new ProjectReadListResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (request.OrganizationUid != currentUser.OrganizationUid) { response.SetInvalid(); return(response); } Expression <Func <Project, bool> > filter = x => x.OrganizationId == currentUser.OrganizationId; Expression <Func <Project, object> > orderByColumn = x => x.Id; if (request.SearchTerm.IsNotEmpty()) { filter = x => x.Name.Contains(request.SearchTerm) && x.OrganizationId == currentUser.OrganizationId; } List <Project> entities; if (request.PagingInfo.Skip < 1) { entities = await _projectRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending); } else { entities = await _projectRepository.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 = _projectFactory.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 _projectRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }
public async Task <IActionResult> ProjectListData(Guid id, int skip, int take) { var organizationUid = id; if (organizationUid.IsEmptyGuid()) { return(Forbid()); } var request = new ProjectReadListRequest(CurrentUser.Id, organizationUid); SetPaging(skip, take, request); var response = await _projectService.GetProjects(request); if (response.Status.IsNotSuccess) { return(NotFound()); } var result = new DataResult(); result.AddHeaders("project_name", "url", "label_count", "is_active", "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($"/Project/Detail/{item.Uid}", item.Name)}{DataResult.SEPARATOR}"); stringBuilder.Append($"{result.PrepareLink(item.Url)}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.LabelCount}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.IsActive}{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 async Task <IActionResult> SelectData() { var request = new ProjectReadListRequest(CurrentUser.Id, CurrentUser.OrganizationUid); var response = await _projectService.GetProjects(request); if (response.Status.IsNotSuccess) { return(null); } var items = new List <SelectResult>(); for (var i = 0; i < response.Items.Count; i++) { var item = response.Items[i]; items.Add(new SelectResult(item.Uid.ToUidString(), $"{item.Name}")); } return(Json(items)); }