public ActionResult SliderSetup(MiniSiteSliderModel model) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(RedirectToRoute("HomePage")); } if (_workContext.CurrentCustomer.UserMiniSite == null) { return(RedirectToRoute("HomePage")); } if (ModelState.IsValid) { var miniSite = _workContext.CurrentCustomer.UserMiniSite; var sliderItems = miniSite.SliderItems; var item = sliderItems.Where(x => x.SlideNumber == 1).FirstOrDefault(); if (item != null) { if (item.PictureId != model.Picture1Id) { if (item.PictureId != 0) { _pictureService.DeletePicture(_pictureService.GetPictureById(item.PictureId)); } item.PictureId = model.Picture1Id; } _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title1, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text1, model.SelectedLanguageId); if (!String.IsNullOrEmpty(model.Link1)) { Match match = Regex.Match(model.Link1, @"^http(s?)://\S+$"); model.Link1 = match.Success ? model.Link1 : "http://" + model.Link1; } item.Url = model.Link1; _sliderItemService.Update(item); } else { item = new SliderItem(); item.SlideNumber = 1; item.PictureId = model.Picture1Id; if (!String.IsNullOrEmpty(model.Link1)) { Match match = Regex.Match(model.Link1, @"^http(s?)://\S+$"); model.Link1 = match.Success ? model.Link1 : "http://" + model.Link1; } item.Url = model.Link1; item.UserMiniSiteId = miniSite.Id; _sliderItemService.Insert(item); _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title1, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text1, model.SelectedLanguageId); } item = sliderItems.Where(x => x.SlideNumber == 2).FirstOrDefault(); if (item != null) { if (item.PictureId != model.Picture2Id) { if (item.PictureId != 0) { _pictureService.DeletePicture(_pictureService.GetPictureById(item.PictureId)); } item.PictureId = model.Picture2Id; } _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title2, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text2, model.SelectedLanguageId); if (!String.IsNullOrEmpty(model.Link2)) { Match match = Regex.Match(model.Link2, @"^http(s?)://\S+$"); model.Link2 = match.Success ? model.Link2 : "http://" + model.Link2; } item.Url = model.Link2; _sliderItemService.Update(item); } else { item = new SliderItem(); item.SlideNumber = 2; item.PictureId = model.Picture2Id; if (!String.IsNullOrEmpty(model.Link2)) { Match match = Regex.Match(model.Link2, @"^http(s?)://\S+$"); model.Link2 = match.Success ? model.Link2 : "http://" + model.Link2; } item.Url = model.Link2; item.UserMiniSiteId = miniSite.Id; _sliderItemService.Insert(item); _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title2, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text2, model.SelectedLanguageId); } item = sliderItems.Where(x => x.SlideNumber == 3).FirstOrDefault(); if (item != null) { if (item.PictureId != model.Picture3Id) { if (item.PictureId != 0) { _pictureService.DeletePicture(_pictureService.GetPictureById(item.PictureId)); } item.PictureId = model.Picture3Id; } _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title3, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text3, model.SelectedLanguageId); if (!String.IsNullOrEmpty(model.Link3)) { Match match = Regex.Match(model.Link3, @"^http(s?)://\S+$"); model.Link3 = match.Success ? model.Link3 : "http://" + model.Link3; } item.Url = model.Link3; _sliderItemService.Update(item); } else { item = new SliderItem(); item.SlideNumber = 3; item.PictureId = model.Picture3Id; if (!String.IsNullOrEmpty(model.Link3)) { Match match = Regex.Match(model.Link3, @"^http(s?)://\S+$"); model.Link3 = match.Success ? model.Link3 : "http://" + model.Link3; } item.Url = model.Link3; item.UserMiniSiteId = miniSite.Id; _sliderItemService.Insert(item); _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title3, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text3, model.SelectedLanguageId); } item = sliderItems.Where(x => x.SlideNumber == 4).FirstOrDefault(); if (item != null) { if (item.PictureId != model.Picture4Id) { if (item.PictureId != 0) { _pictureService.DeletePicture(_pictureService.GetPictureById(item.PictureId)); } item.PictureId = model.Picture4Id; } _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title4, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text4, model.SelectedLanguageId); if (!String.IsNullOrEmpty(model.Link4)) { Match match = Regex.Match(model.Link4, @"^http(s?)://\S+$"); model.Link4 = match.Success ? model.Link4 : "http://" + model.Link4; } item.Url = model.Link4; _sliderItemService.Update(item); } else { item = new SliderItem(); item.SlideNumber = 4; item.PictureId = model.Picture4Id; if (!String.IsNullOrEmpty(model.Link4)) { Match match = Regex.Match(model.Link4, @"^http(s?)://\S+$"); model.Link4 = match.Success ? model.Link4 : "http://" + model.Link4; } item.Url = model.Link4; item.UserMiniSiteId = miniSite.Id; _sliderItemService.Insert(item); _localizedEntityService.SaveLocalizedValue(item, x => x.TitleText, model.Title4, model.SelectedLanguageId); _localizedEntityService.SaveLocalizedValue(item, x => x.ShortText, model.Text4, model.SelectedLanguageId); } } var lang = _languageService.GetLanguageById(model.SelectedLanguageId); model.SelectedLanguage = new LanguageModel() { Name = lang.Name, LanguageCulture = lang.LanguageCulture, Id = lang.Id }; model.AviableLanguages = new List <LanguageModel>(); var language = _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault(); model.AviableLanguages.Add(new LanguageModel() { Name = language.Name, LanguageCulture = language.LanguageCulture, Id = language.Id }); language = _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "en").FirstOrDefault(); model.AviableLanguages.Add(new LanguageModel() { Name = language.Name, LanguageCulture = language.LanguageCulture, Id = language.Id }); model.SelectedLanguageId = lang.Id; return(View(model)); }
public ActionResult SliderSetup(int?languageId) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(RedirectToRoute("HomePage")); } if (_workContext.CurrentCustomer.UserMiniSite == null) { return(RedirectToRoute("HomePage")); } if (!languageId.HasValue) { languageId = _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault().Id; } var model = new MiniSiteSliderModel(); var slides = _workContext.CurrentCustomer.UserMiniSite.SliderItems; var sliderItem = slides.Where(x => x.SlideNumber == 1).FirstOrDefault(); if (sliderItem != null) { model.Link1 = sliderItem.Url; model.Picture1Id = sliderItem.PictureId; model.Text1 = sliderItem.GetLocalized(x => x.ShortText, languageId.Value, false); model.Title1 = sliderItem.GetLocalized(x => x.TitleText, languageId.Value, false); } sliderItem = slides.Where(x => x.SlideNumber == 2).FirstOrDefault(); if (sliderItem != null) { model.Link2 = sliderItem.Url; model.Picture2Id = sliderItem.PictureId; model.Text2 = sliderItem.GetLocalized(x => x.ShortText, languageId.Value, false); model.Title2 = sliderItem.GetLocalized(x => x.TitleText, languageId.Value, false); } sliderItem = slides.Where(x => x.SlideNumber == 3).FirstOrDefault(); if (sliderItem != null) { model.Link3 = sliderItem.Url; model.Picture3Id = sliderItem.PictureId; model.Text3 = sliderItem.GetLocalized(x => x.ShortText, languageId.Value, false); model.Title3 = sliderItem.GetLocalized(x => x.TitleText, languageId.Value, false); } sliderItem = slides.Where(x => x.SlideNumber == 4).FirstOrDefault(); if (sliderItem != null) { model.Link4 = sliderItem.Url; model.Picture4Id = sliderItem.PictureId; model.Text4 = sliderItem.GetLocalized(x => x.ShortText, languageId.Value, false); model.Title4 = sliderItem.GetLocalized(x => x.TitleText, languageId.Value, false); } var lang = _languageService.GetLanguageById(languageId.Value); model.SelectedLanguage = new LanguageModel() { Name = lang.Name, LanguageCulture = lang.LanguageCulture, Id = lang.Id }; model.AviableLanguages = new List <LanguageModel>(); var language = _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault(); model.AviableLanguages.Add(new LanguageModel() { Name = language.Name, LanguageCulture = language.LanguageCulture, Id = language.Id }); language = _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "en").FirstOrDefault(); model.AviableLanguages.Add(new LanguageModel() { Name = language.Name, LanguageCulture = language.LanguageCulture, Id = language.Id }); model.SelectedLanguageId = lang.Id; return(View(model)); }