private void AddBrandLanguagesAndMessageTemplates(Data.Brand brand, BrandLanguagesAssigned message) { brand.DefaultLanguageCode = message.DefaultLanguageCode; var newLanguages = message.Languages.Where(x => brand.Languages.All(y => y.Code != x.Code)); newLanguages.ForEach(newLanguage => { var language = _repository.Languages.Single(x => x.Code == newLanguage.Code); brand.Languages.Add(language); AddDefaultMessageTemplates(brand, language); }); }
private void RemoveBrandLanguagesAndMessageTemplates(Data.Brand brand, BrandLanguagesAssigned message) { var oldLanguages = brand.Languages.Where(x => message.Languages.All(y => y.Code != x.Code)).ToArray(); oldLanguages.ForEach(oldLanguage => { var messageTemplates = _repository.MessageTemplates.Where(x => x.BrandId == brand.Id && x.LanguageCode == oldLanguage.Code); messageTemplates.ForEach(messageTemplate => _repository.MessageTemplates.Remove(messageTemplate)); brand.Languages.Remove(oldLanguage); }); }
private void AddDefaultMessageTemplates(Data.Brand brand, Language language) { var culture = CultureInfo.GetCultureInfo(language.Code); var resourceSet = DefaultMessageTemplates.ResourceManager.GetResourceSet(culture, true, true); foreach (DictionaryEntry resource in resourceSet) { var messageTemplate = JsonConvert.DeserializeObject <MessageTemplate>((string)resource.Value); messageTemplate.BrandId = brand.Id; messageTemplate.Brand = brand; messageTemplate.LanguageCode = language.Code; messageTemplate.Language = language; messageTemplate.Status = Status.Active; messageTemplate.Activated = messageTemplate.Created = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId); messageTemplate.ActivatedBy = messageTemplate.CreatedBy = "System"; _repository.MessageTemplates.Add(messageTemplate); } }