public static T OfFormat <T, TR>(this ITranslatableEntity <T, TR> entity, UserService userService) where T : ITranslatableEntity <T, TR> where TR : TranslatableEntityTranslation <T> { entity = entity.OfCulture(userService.Culture); if (entity is EntitySaleable saleable) { if (saleable.IsPaid) { saleable.OfCurrency(userService.Currency); if (userService.User.Sales.All(x => x.EntityId != saleable.Id)) { if (entity.Content is ITranslationWithUrl withUrl) { withUrl.Url = null; } } } else if (saleable is Video saleableVideo && saleableVideo.IsInPaidPlaylist) { if (userService.User.Sales.All(x => x.EntityId != saleableVideo.PlaylistId)) { if (saleableVideo.Content is ITranslationWithUrl withUrl) { withUrl.Url = null; } } } } return((T)entity); }
public static T OfCulture <T, TR>(this ITranslatableEntity <T, TR> entity, Culture culture) where T : ITranslatableEntity <T, TR> where TR : TranslatableEntityTranslation <T> { if (entity.Translations.Count > 0) { entity.Content = entity.Translations.FirstOrDefault(tr => tr.Culture.Key == culture.Key) ?? entity.Translations.FirstOrDefault(x => x.Culture.Key == Culture.Default.Key) ?? entity.Translations.FirstOrDefault(); } return((T)entity); }
public static bool IsTranslatableEntityHasTranslation <T, TR>(ITranslatableEntity <T, TR> entity, Culture culture = null) where T : ITranslatableEntity <T, TR> where TR : TranslatableEntityTranslation <T> => culture == null ? entity.Translations.Count > 0 : entity.Translations.Any(x => x.Culture.Key == culture.Key);