using System.Linq; using xCategoryService.Models.Dtos; using xCategoryService.Providers.Dtos; using xCommons.Extensions; namespace xCategoryService.Extensions { /// /// Extensions Method Related to XSubCategoryResourceDto ... /// public static class XSubCategoryResourceExtensions { /// /// Extract Available Languages ... /// /// /// public static string[] ExtractLanguages( this XSubCategoryResourceDto source ) { // var result = new string[] { }; // // Validate ... if (!source.IsNullOrDefault()) { return result; } // result = source.Titles.Locales.Select(x => x.Language) .Union(source.Descriptions.Locales.Select(x => x.Language)) .Distinct() .ToArray(); // return result; } /// /// Check Has Locale or not ... /// /// /// /// public static bool HasLocale( this XSubCategoryResourceDto source, string language ) { // var result = !language.IsNullOrEmpty() && !source.IsNullOrDefault() && source.Titles.Locales .Any(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // return result; } /// /// Get Item Translation ... /// /// /// /// public static XSubCategoryDto GetTranslate( this XSubCategoryResourceDto source, string language ) { // XSubCategoryDto result = null; // var isValid = source .HasLocale(language); if (!isValid) { return result; } // var titleLocale = source.Titles.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); var descriptionLocale = source.Descriptions.Locales .FirstOrDefault(l => l.Language .Equals( language, System.StringComparison.InvariantCultureIgnoreCase)); // isValid = !titleLocale.IsNullOrDefault(); if (!isValid) { return result; } // result = source.Item; result.Title = titleLocale.Value; result.Description = descriptionLocale.IsNullOrDefault() ? string.Empty : descriptionLocale.Value; // return result; } } }