Esempio n. 1
0
        public async Task <IActionResult> PendingTranslationsData(Guid id, int skip, int take)
        {
            var organizationUid = id;

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

            var request = new OrganizationPendingTranslationReadListRequest(CurrentUser.Id, organizationUid);

            SetPaging(skip, take, request);

            var response = await _organizationService.GetPendingTranslations(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));
        }
        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.SetInvalid();
                response.ErrorMessages.Add("organization_not_found");
                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 < 2;

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

            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);
        }
        public static OrganizationPendingTranslationReadListRequest GetOrganizationPendingTranslationReadListRequest()
        {
            var request = new OrganizationPendingTranslationReadListRequest(CurrentUserId, UidOne);

            return(request);
        }