Пример #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 <OrganizationPendingTranslationReadListResponse> GetPendingTranslations(OrganizationPendingTranslationReadListRequest request)
        {
            var response = new OrganizationPendingTranslationReadListResponse();

            var organization = await _organizationRepository.Select(x => x.Uid == request.OrganizationUid);

            if (organization.IsNotExist())
            {
                response.SetInvalidBecauseEntityNotFound();
                return(response);
            }

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

            if (request.OrganizationUid != currentUser.OrganizationUid)
            {
                response.SetInvalid();
                return(response);
            }

            Expression <Func <Label, bool> > filter = x => x.OrganizationId == organization.Id &&
                                                      x.LabelTranslationCount == 0;
            Expression <Func <Label, object> > orderByColumn = x => x.Id;

            if (request.SearchTerm.IsNotEmpty())
            {
                filter = x => x.Name.Contains(request.SearchTerm) &&
                         x.OrganizationId == organization.Id &&
                         x.LabelTranslationCount == 0;
            }

            List <Label> entities;

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