Skip to content

Commit

Permalink
adding generic Haslanguage checker
Browse files Browse the repository at this point in the history
  • Loading branch information
RudiThoeni committed Sep 26, 2024
1 parent 286b222 commit 7e9e187
Showing 1 changed file with 105 additions and 1 deletion.
106 changes: 105 additions & 1 deletion Helper/Generic/HasLanguageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,111 @@ private static void FixDetailLanguageField(ILanguage mydetail, string language)
if (String.IsNullOrEmpty(mydetail.Language))
mydetail.Language = language;
}


//Generic
public static void CheckMyInsertedLanguages<T>(this T mypoiactivity, List<string>? availablelanguages) where T : IHasLanguage, IContactInfosAware, IDetailInfosAware
{
if (availablelanguages == null || availablelanguages.Count == 0)
availablelanguages = new List<string>() { "de", "it", "en", "nl", "cs", "pl", "fr", "ru" };

if (mypoiactivity.HasLanguage == null)
mypoiactivity.HasLanguage = new List<string>();

//Detail, ImageGallery, ContactInfos, AdditionalArticleInfos,
foreach (string language in availablelanguages)
{
if (mypoiactivity.Detail.ContainsKey(language) || mypoiactivity.ContactInfos.ContainsKey(language)) // || mypoiactivity.AdditionalPoiInfos.ContainsKey(language))
{
bool removelang = true;

if (mypoiactivity.Detail.ContainsKey(language) && mypoiactivity.Detail[language] != null)
{
var detailvalues = mypoiactivity.Detail[language];

FixDetailLanguageField(detailvalues, language);
FixDetailBaseAndIntroText(detailvalues);

if (!String.IsNullOrEmpty(detailvalues.AdditionalText))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.BaseText))
if (!String.IsNullOrEmpty(detailvalues.BaseText.Trim()))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.GetThereText))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.Header))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.IntroText))
if (!String.IsNullOrEmpty(detailvalues.IntroText.Trim()))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.SubHeader))
removelang = false;
if (!String.IsNullOrEmpty(detailvalues.Title))
removelang = false;
}

if (mypoiactivity.ContactInfos.ContainsKey(language) && mypoiactivity.ContactInfos[language] != null)
{
var contactvalues = mypoiactivity.ContactInfos[language];

FixDetailLanguageField(contactvalues, language);

if (!String.IsNullOrEmpty(contactvalues.Address))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.City))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.CompanyName))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.CountryCode))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.CountryName))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Email))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Faxnumber))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Givenname))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.LogoUrl))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.NamePrefix))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Phonenumber))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Surname))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Tax))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Url))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.Vat))
removelang = false;
if (!String.IsNullOrEmpty(contactvalues.ZipCode))
removelang = false;
}

//Add Language
if (removelang == false)
{
if (!mypoiactivity.HasLanguage.Contains(language))
mypoiactivity.HasLanguage.Add(language);
}
//Remove Language
else if (removelang == true)
{
if (mypoiactivity.Detail.ContainsKey(language))
mypoiactivity.Detail.Remove(language);

if (mypoiactivity.ContactInfos.ContainsKey(language))
mypoiactivity.ContactInfos.Remove(language);

if (mypoiactivity.HasLanguage.Contains(language))
mypoiactivity.HasLanguage.Remove(language);
}
}
}
}


//Check Language for Example DataModel
public static void CheckMyInsertedLanguages(this Example example, List<string> availablelanguages)
{
Expand Down

0 comments on commit 7e9e187

Please sign in to comment.