public List <SourceWithTranslation> GetExact(long userId, long sourceId, long translationId) { if (IdValidator.IsValid(userId)) { //пользователя знаем - может быть это его энтити - попробуем найти List <SourceWithTranslation> result = GetUserEntities(userId, sourceId, translationId); if (result.Count > 0) { return(result); } } Tuple <long, byte[], PronunciationEntity, PronunciationEntity> sourceAndTranslationWithId = GetBySourceAndTranslation(sourceId, translationId); long id = sourceAndTranslationWithId.Item1; PronunciationEntity source = sourceAndTranslationWithId.Item3; PronunciationEntity translation = sourceAndTranslationWithId.Item4; if (IdValidator.IsInvalid(id) || source == null || translation == null) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat( "BaseRandomQuery.GetExact для пользователя {0} не удалось получить данные с идентификаторами {1} и {2}", userId, sourceId, translationId); return(null); } long sourceLanguageId = source.Id == sourceId ? source.LanguageId : translation.LanguageId; SourceWithTranslation sentence = ConverterEntities.ConvertToSourceWithTranslation(id, sourceAndTranslationWithId .Item2, sourceLanguageId, source, translation); sentence.IsCurrent = true; return(new List <SourceWithTranslation> { sentence }); }
/// <summary> /// Из двух энтитей создает энтити с переводом /// </summary> /// <param name="id">уникальный идентификатор энтити с переводом</param> /// <param name="image">изображение, если есть</param> /// <param name="sourceLanguageId">язык, с которого нужно переводить</param> /// <param name="pronunciation1">первая энтити</param> /// <param name="pronunciation2">втора энтити</param> /// <returns>энтити с переводом</returns> public static SourceWithTranslation ConvertToSourceWithTranslation(long id, byte[] image, long sourceLanguageId, PronunciationEntity pronunciation1, PronunciationEntity pronunciation2) { var result = new SourceWithTranslation(); PronunciationEntity source; PronunciationEntity translation; if (pronunciation1.LanguageId == sourceLanguageId) { source = pronunciation1; translation = pronunciation2; } else { source = pronunciation2; translation = pronunciation1; } result.Set(id, source, translation); result.HasImage = image != null && image.Length > 0; return(result); }
internal PronunciationForUser(PronunciationEntity pronunciation) : this( pronunciation.Id, pronunciation.Text, EnumerableValidator.IsNotNullAndNotEmpty(pronunciation.Pronunciation), pronunciation.LanguageId) { }
public WordWithTranslation(PronunciationEntity word) { Source = new PronunciationForUser(word); Translations = new List <PronunciationForUser>(); }
internal void Set(long id, PronunciationEntity source, PronunciationEntity translation) { Set(id, new PronunciationForUser(source), new PronunciationForUser(translation)); }