public async Task CreateOrUpdateOptionsAsync(WebsiteOptionCategoryDto model) { var options = await _factory.MakeAsync(model); if(!options.Any()) return; options = options.ToList(); foreach(var item in options) { var entity = await _repository.GetOptionAsync( model.Category, item.Key, model.LangId) ?? new WebsiteOption(); entity.Title = item.Title; entity.WebsiteId = _websiteInfo.Id; entity.Key = item.Key; entity.Value = item.Value; entity.OrderNum = item.OrderNum; if(entity.Id == 0) { entity.Category = model.Category; entity.LangId = model.LangId; entity.Status = EntityStatus.Enabled; _repository.MarkForAdd(entity); } else _repository.MarkForUpdate(entity); } await _repository.SaveChangesAsync(); }
//TODO : Temporary Method public async Task CreateSocialNetworksOptionsAsync() { WebsiteSocialNetworksSetting socialNetworkSetting = null; if (_setting.WebsiteSeedInfo.Options?.SocialNetworks != null) { socialNetworkSetting = _setting.WebsiteSeedInfo.Options.SocialNetworks; } var socialNetworkOptions = new WebsiteOptionCategoryDto { Category = WebsiteOptionCategoryNames.SocialNetwork, Items = new List <WebsiteOptionCategoryItemDto> { new WebsiteOptionCategoryItemDto { Key = nameof(WebsiteSocialNetworkDto.Facebook), OrderNum = 1, Title = nameof(WebsiteSocialNetworkDto.Facebook), Value = socialNetworkSetting != null ? socialNetworkSetting.Facebook : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 2, Key = nameof(WebsiteSocialNetworkDto.Instagram), Title = nameof(WebsiteSocialNetworkDto.Instagram), Value = socialNetworkSetting != null ? socialNetworkSetting.Instagram : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 3, Key = nameof(WebsiteSocialNetworkDto.LinkedIn), Title = nameof(WebsiteSocialNetworkDto.LinkedIn), Value = socialNetworkSetting != null ? socialNetworkSetting.LinkedIn : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 4, Key = nameof(WebsiteSocialNetworkDto.Telegram), Title = nameof(WebsiteSocialNetworkDto.Telegram), Value = socialNetworkSetting != null ? socialNetworkSetting.Telegram : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 5, Key = nameof(WebsiteSocialNetworkDto.Twitter), Title = nameof(WebsiteSocialNetworkDto.Twitter), Value = socialNetworkSetting != null ? socialNetworkSetting.Twitter : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 6, Key = nameof(WebsiteSocialNetworkDto.Whatsapp), Title = nameof(WebsiteSocialNetworkDto.Whatsapp), Value = socialNetworkSetting != null ? socialNetworkSetting.Whatsapp : string.Empty } } }; await CreateOrUpdateOptionsAsync(socialNetworkOptions); }
//TODO : Temporary Method public async Task CreateContactOptionsAsync() { var faLang = await _langRepository.GetByLangKeyAsync(Language.KEY_fa_IR); WebsiteContactSetting contactInfo = null; if (_setting.WebsiteSeedInfo.Options?.Contact != null) { contactInfo = _setting.WebsiteSeedInfo.Options.Contact; } var contactOptions = new WebsiteOptionCategoryDto { LangId = faLang.Id, Items = new List <WebsiteOptionCategoryItemDto> { new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = nameof(WebsiteContactInfoDto.Address1), Title = "آدرس 1", Value = contactInfo != null ? contactInfo.Address1 : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 2, Key = nameof(WebsiteContactInfoDto.Address2), Title = "آدرس 2", Value = contactInfo != null ? contactInfo.Address2 : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 3, Title = "متن کپی رایت", Key = nameof(WebsiteContactInfoDto.Copyright), Value = contactInfo != null ? contactInfo.Copyright : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 4, Key = nameof(WebsiteContactInfoDto.Email), Title = "آدرس ایمیل", Value = contactInfo != null ? contactInfo.Email : string.Empty }, new WebsiteOptionCategoryItemDto { OrderNum = 5, Key = nameof(WebsiteContactInfoDto.Phones), Title = "شماره های تماس", Value = contactInfo != null ? contactInfo.Phones : string.Empty } }, Category = WebsiteOptionCategoryNames.ContactInfo }; await CreateOrUpdateOptionsAsync(contactOptions); }
public async Task <IEnumerable <WebsiteOption> > MakeAsync(WebsiteOptionCategoryDto model) { model.CheckArgumentIsNull(nameof(model)); var result = new List <WebsiteOption>(); foreach (var item in model.Items) { result.Add(new WebsiteOption { LangId = model.LangId, Category = model.Category, WebsiteId = _websiteInfo.Id, Key = item.Key, OrderNum = item.OrderNum, Status = EntityStatus.Enabled, Title = item.Title, Value = item.Value }); } return(await Task.FromResult( result.ToList() )); }
/// <summary> /// Seed Website's options with the seed data from appsetting.json file. /// </summary> /// <returns></returns> public async Task SeedOptionsAsync() { if (_setting == null) { throw new WebsiteOptionsSeedException(); } var lang = await _langRepository.GetByLangKeyAsync(_setting.LangKey); //Create or Update General options with Seed data from appsetting var generalOptions = new WebsiteOptionCategoryDto { LangId = lang.Id, Category = WebsiteOptionCategoryNames.General, Items = new List <WebsiteOptionCategoryItemDto> { new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = WebsiteOptionsKey.LogoPath, Title = WebsiteOptionsText.Website_Logo, Value = _setting.LogoPath }, new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = WebsiteOptionsKey.FavIconPath, Title = WebsiteOptionsText.Website_Logo, Value = _setting.LogoPath }, } }; await _websiteOptionService.CreateOrUpdateOptionsAsync(generalOptions); //Create or Update Contact options with Seed data from appsetting var contact = _setting.Contact; var contactOptions = new WebsiteOptionCategoryDto { LangId = lang.Id, Category = WebsiteOptionCategoryNames.ContactInfo, Items = new List <WebsiteOptionCategoryItemDto> { new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = WebsiteOptionsKey.Contact_Address1, Title = WebsiteOptionsText.Address1, Value = contact?.Address1 }, new WebsiteOptionCategoryItemDto { OrderNum = 2, Key = WebsiteOptionsKey.Contact_Address2, Title = WebsiteOptionsText.Address2, Value = contact?.Address2 }, new WebsiteOptionCategoryItemDto { OrderNum = 3, Key = WebsiteOptionsKey.Contact_Copyright, Title = WebsiteOptionsText.Copyright, Value = contact?.Copyright }, new WebsiteOptionCategoryItemDto { OrderNum = 4, Key = WebsiteOptionsKey.Contact_Phones, Title = WebsiteOptionsText.Phones, Value = contact?.Phones }, new WebsiteOptionCategoryItemDto { OrderNum = 5, Key = WebsiteOptionsKey.Contact_Email, Title = WebsiteOptionsText.Email, Value = contact?.Email }, } }; await _websiteOptionService.CreateOrUpdateOptionsAsync(contactOptions); //Create or Update SocialNetwork options with Seed data from appsetting var socialNetworks = _setting.SocialNetworks; var socialNetworksOptions = new WebsiteOptionCategoryDto { LangId = lang.Id, Category = WebsiteOptionCategoryNames.SocialNetwork, Items = new List <WebsiteOptionCategoryItemDto> { new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = WebsiteOptionsKey.Social_Telegram, Title = WebsiteOptionsText.Social_Telegram, Value = socialNetworks?.Telegram }, new WebsiteOptionCategoryItemDto { OrderNum = 2, Key = WebsiteOptionsKey.Social_Instagram, Title = WebsiteOptionsText.Social_Insta, Value = socialNetworks?.Instagram }, new WebsiteOptionCategoryItemDto { OrderNum = 3, Key = WebsiteOptionsKey.Social_LinkedIn, Title = WebsiteOptionsText.Social_LinkedIn, Value = socialNetworks?.LinkedIn }, new WebsiteOptionCategoryItemDto { OrderNum = 4, Key = WebsiteOptionsKey.Social_WhatsApp, Title = WebsiteOptionsText.Social_Whatsapp, Value = socialNetworks?.Whatsapp }, new WebsiteOptionCategoryItemDto { OrderNum = 5, Key = WebsiteOptionsKey.Social_Twitter, Title = WebsiteOptionsText.Social_Twitter, Value = socialNetworks?.Twitter }, new WebsiteOptionCategoryItemDto { OrderNum = 6, Key = WebsiteOptionsKey.Social_Facebook, Title = WebsiteOptionsText.Social_Facebook, Value = socialNetworks?.Facebook }, new WebsiteOptionCategoryItemDto { OrderNum = 1, Key = WebsiteOptionsKey.Social_YouTube, Title = WebsiteOptionsText.Social_YouTube, Value = socialNetworks?.YouTube } } }; await _websiteOptionService.CreateOrUpdateOptionsAsync(socialNetworksOptions); }