public async Task <LabelTranslationReadListResponse> GetTranslation(LabelTranslationReadRequest request) { var response = new LabelTranslationReadListResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); var labelTranslation = await _labelTranslationRepository.Select(x => x.Uid == request.LabelTranslationUid); if (labelTranslation.IsNotExist()) { response.SetInvalid(); response.ErrorMessages.Add("label_translation_not_found"); return(response); } if (labelTranslation.OrganizationId != currentUser.OrganizationId) { response.SetFailed(); return(response); } var language = await _languageRepository.SelectById(labelTranslation.LanguageId); if (language.IsNotExist()) { response.SetFailed(); return(response); } response.Item = _labelTranslationFactory.CreateDtoFromEntity(labelTranslation, language); response.Status = ResponseStatus.Success; return(response); }
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); }