public async Task <IActionResult> DownloadTranslations(Guid id) { var labelUid = id; if (labelUid.IsEmptyGuid()) { return(NoContent()); } var labelRequest = new LabelTranslationReadListRequest(CurrentUser.Id, labelUid); var translations = await _labelService.GetTranslations(labelRequest); if (translations.Status.IsNotSuccess) { return(NoContent()); } var sb = new StringBuilder(); sb.AppendLine("language,translation"); for (var i = 0; i < translations.Items.Count; i++) { var item = translations.Items[i]; sb.AppendLine(item.LanguageIsoCode2 + "," + item.Translation); } CurrentUser.IsActionSucceed = true; return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "translations.csv")); }
public async Task <IActionResult> LabelTranslationListData(Guid id, int skip, int take) { var labelUid = id; if (labelUid.IsEmptyGuid()) { return(Forbid()); } var request = new LabelTranslationReadListRequest(CurrentUser.Id, labelUid); SetPaging(skip, take, request); var response = await _labelService.GetTranslations(request); if (response.Status.IsNotSuccess) { return(NotFound()); } var result = new DataResult(); result.AddHeaders("language", "translation", ""); 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.PrepareImage($"{item.LanguageIconUrl}", item.LanguageName)} {item.LanguageName}{DataResult.SEPARATOR}"); stringBuilder.Append($"{item.Translation}{DataResult.SEPARATOR}"); stringBuilder.Append($"{result.PrepareLink($"/Label/LabelTranslationEdit/{item.Uid}", Localizer.Localize("edit"), true)}"); stringBuilder.Append($"{result.PrepareLink($"/Label/LabelTranslationRevisions/{item.Uid}", Localizer.Localize("revisions_link"), true)}{DataResult.SEPARATOR}"); result.Data.Add(stringBuilder.ToString()); } result.PagingInfo = response.PagingInfo; result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS; return(Json(result)); }
public async Task <LabelTranslationReadListResponse> GetTranslations(LabelTranslationReadListRequest request) { var response = new LabelTranslationReadListResponse(); var label = await _labelRepository.Select(x => x.Uid == request.LabelUid); if (label.IsNotExist()) { response.SetInvalid(); response.ErrorMessages.Add("label_not_active"); return(response); } var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (label.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } Expression <Func <LabelTranslation, bool> > filter = x => x.LabelId == label.Id; if (request.SearchTerm.IsNotEmpty()) { filter = x => x.Name.Contains(request.SearchTerm) && x.ProjectId == label.Id; } List <LabelTranslation> entities; if (request.PagingInfo.Skip < 1) { entities = await _labelTranslationRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, x => x.Uid, request.PagingInfo.IsAscending); } else { entities = await _labelTranslationRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, x => x.Id, request.PagingInfo.IsAscending); } if (entities != null) { var languages = await _languageRepository.SelectAll(null); for (var i = 0; i < entities.Count; i++) { var entity = entities[i]; var language = languages.Find(x => x.Id == entity.LanguageId); if (language != null) { var dto = _labelTranslationFactory.CreateDtoFromEntity(entity, language); response.Items.Add(dto); } else { response.WarningMessages.Add(entity.LanguageName + " not found!"); } } } 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 _labelTranslationRepository.Count(filter); response.Status = ResponseStatus.Success; return(response); }
public static LabelTranslationReadListRequest GetLabelTranslationReadListRequest() { var request = new LabelTranslationReadListRequest(CurrentUserId, UidOne); return(request); }