protected virtual void PrepareLanguagesModel(NewsItemModel model) { if (model == null) throw new ArgumentNullException("model"); var languages = _languageService.GetAllLanguages(true); foreach (var language in languages) { model.AvailableLanguages.Add(new SelectListItem { Text = language.Name, Value = language.Id.ToString() }); } }
protected virtual void PrepareStoresMappingModel(NewsItemModel model, NewsItem newsItem, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (newsItem != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(newsItem); } } }
protected virtual void PrepareStoresMappingModel(NewsItemModel model, NewsItem newsItem, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (!excludeProperties && newsItem != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(newsItem).ToList(); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = model.SelectedStoreIds.Contains(store.Id) }); } }
protected virtual void SaveStoreMappings(NewsItem newsItem, NewsItemModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(newsItem); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new store if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(newsItem, store.Id); } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }
public ActionResult Edit(NewsItemModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var newsItem = _newsService.GetNewsById(model.Id); if (newsItem == null) //No news item found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { newsItem = model.ToEntity(newsItem); _newsService.UpdateNews(newsItem); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Updated")); return continueEditing ? RedirectToAction("Edit", new { id = newsItem.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); return View(model); }
public ActionResult Create(NewsItemModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); if (ModelState.IsValid) { var newsItem = model.ToEntity(); newsItem.CreatedOnUtc = DateTime.UtcNow; _newsService.InsertNews(newsItem); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Added")); return continueEditing ? RedirectToAction("Edit", new { id = newsItem.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); return View(model); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); ViewBag.AllLanguages = _languageService.GetAllLanguages(true); var model = new NewsItemModel(); //default values model.Published = true; model.AllowComments = true; return View(model); }
public ActionResult Edit(NewsItemModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var newsItem = _newsService.GetNewsById(model.Id); if (newsItem == null) //No news item found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { newsItem = model.ToEntity(newsItem); newsItem.StartDateUtc = model.StartDate; newsItem.EndDateUtc = model.EndDate; newsItem.Stores = model.SelectedStoreIds != null ? model.SelectedStoreIds.ToList() : new List<int>(); var seName = newsItem.ValidateSeName(model.SeName, model.Title, true); newsItem.SeName = seName; _newsService.UpdateNews(newsItem); //search engine name _urlRecordService.SaveSlug(newsItem, seName, newsItem.LanguageId); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return RedirectToAction("Edit", new {id = newsItem.Id}); } return RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); //Store PrepareStoresMappingModel(model, newsItem, true); return View(model); }
public ActionResult Create(NewsItemModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); if (ModelState.IsValid) { var newsItem = model.ToEntity(); newsItem.StartDateUtc = model.StartDate; newsItem.EndDateUtc = model.EndDate; newsItem.CreatedOnUtc = DateTime.UtcNow; _newsService.InsertNews(newsItem); //search engine name var seName = newsItem.ValidateSeName(model.SeName, model.Title, true); _urlRecordService.SaveSlug(newsItem, seName, newsItem.LanguageId); //Stores SaveStoreMappings(newsItem, model); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.News.NewsItems.Added")); return continueEditing ? RedirectToAction("Edit", new { id = newsItem.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = _languageService.GetAllLanguages(true); //Stores PrepareStoresMappingModel(model, null, true); return View(model); }
protected virtual void PrepareNewsModel(NewsItemModel model, NewsItem newsItem) { if (model == null) throw new ArgumentNullException("model"); if (newsItem != null) { var allCategories = _catalogueService.GetAllCatalogues(showHidden: true); foreach (var category in allCategories) { model.AvailableCatalogues.Add(new SelectListItem { Text = category.Name, Value = category.Id.ToString() }); } } }
public ActionResult NewsPictureUpdate(NewsItemModel.NewsPictureModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var newsPicture = _newsService.GetNewsPictureById(model.Id); if (newsPicture == null) throw new ArgumentException("No news picture found with the specified id"); newsPicture.DisplayOrder = model.DisplayOrder; _newsService.UpdateNewsPicture(newsPicture); return new NullJsonResult(); }
public ActionResult NewsCatalogueUpdate(NewsItemModel.NewsCatalogueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var newsCatalogue = _catalogueService.GetNewsCataloguesById(model.Id); if (newsCatalogue == null) throw new ArgumentException("No news catalogue mapping found with the specified id"); newsCatalogue.CatalogueId = model.CatalogueId; newsCatalogue.DisplayOrder = model.DisplayOrder; _catalogueService.UpdateNewsCatalogues(newsCatalogue); return new NullJsonResult(); }
public ActionResult NewsCatalogueInsert(NewsItemModel.NewsCatalogueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var newsId = model.NewsId; var catalogueId = model.CatalogueId; var existingNewsCatalogues = _catalogueService.GetNewsCataloguesByCatalogueId(catalogueId, 0, int.MaxValue, true); if (existingNewsCatalogues.FindNewsCatalogues(newsId, catalogueId) == null) { var newsCatalogue = new NewsCatalogues { NewsId = newsId, CatalogueId = catalogueId, DisplayOrder = model.DisplayOrder }; _catalogueService.InsertNewsCatalogues(newsCatalogue); } return new NullJsonResult(); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); var model = new NewsItemModel(); //languages PrepareLanguagesModel(model); //Stores PrepareStoresMappingModel(model, null, false); //default values model.Published = true; model.AllowComments = true; return View(model); }
protected virtual void PrepareAclModel(NewsItemModel model, NewsItem newsItem, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); if (!excludeProperties) { if (newsItem != null) { model.SelectedCustomerRoleIds = newsItem.CustomerRoles.ToArray(); } } }