예제 #1
0
        public async Task <LabelReadListResponse> GetLabels(LabelReadListRequest request)
        {
            var response = new LabelReadListResponse();

            var project = await _projectRepository.Select(x => x.Uid == request.ProjectUid);

            if (project.IsNotExist())
            {
                response.SetInvalid();
                response.ErrorMessages.Add("project_not_found");
                return(response);
            }

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (project.OrganizationId != currentUser.OrganizationId)
            {
                response.SetInvalid();
                return(response);
            }

            Expression <Func <Label, bool> > filter = x => x.ProjectId == project.Id;

            if (request.SearchTerm.IsNotEmpty())
            {
                filter = x => x.Name.Contains(request.SearchTerm) && x.ProjectId == project.Id;
            }

            List <Label> entities;

            if (request.PagingInfo.Skip < 1)
            {
                entities = await _labelRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, x => x.Uid, request.PagingInfo.IsAscending);
            }
            else
            {
                entities = await _labelRepository.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    = _labelFactory.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 _labelRepository.Count(filter);

            response.Status = ResponseStatus.Success;
            return(response);
        }
예제 #2
0
        public async Task <IActionResult> LabelListData(Guid id, int skip, int take)
        {
            var projectUid = id;

            if (projectUid.IsEmptyGuid())
            {
                return(Forbid());
            }

            var request = new LabelReadListRequest(CurrentUser.Id, projectUid);

            SetPaging(skip, take, request);

            var response = await _labelService.GetLabels(request);

            if (response.Status.IsNotSuccess)
            {
                return(NotFound());
            }

            var result = new DataResult();

            result.AddHeaders("label_key", "label_translation_count", "description", "is_active");

            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($"/Label/Detail/{item.Key}", item.Key)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.LabelTranslationCount}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.Description}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.IsActive}{DataResult.SEPARATOR}");

                result.Data.Add(stringBuilder.ToString());
            }

            result.PagingInfo      = response.PagingInfo;
            result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS;

            return(Json(result));
        }
예제 #3
0
        public static LabelReadListRequest GetLabelReadListRequest()
        {
            var request = new LabelReadListRequest(CurrentUserId, UidOne);

            return(request);
        }