public ActionResult Edit(ArticleGroupModel model, bool continueEditing) { var articleGroup = _articleService.GetArticleGroupById(model.Id); if (articleGroup == null || articleGroup.Deleted) //No category found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = articleGroup.PictureId; articleGroup = model.ToEntity(articleGroup); articleGroup.UpdatedOnUtc = DateTime.UtcNow; _articleService.UpdateArticleGroup(articleGroup); //search engine name model.SeName = articleGroup.ValidateSeName(model.SeName, articleGroup.Name, true); _urlRecordService.SaveSlug(articleGroup, model.SeName, 0); //locales UpdateLocales(articleGroup, model); _articleService.UpdateArticleGroup(articleGroup); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != articleGroup.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(articleGroup); //Stores SaveStoreMappings(articleGroup, model); //activity log _customerActivityService.InsertActivity("EditArticleGroup", _localizationService.GetResource("ActivityLog.EditArticleGroup"), articleGroup.Name); SuccessNotification(_localizationService.GetResource("Admin.Plugins.ArticleManagement.ArticleGroups.Updated")); return continueEditing ? RedirectToAction("Edit", new{ id = articleGroup.Id }) : RedirectToAction("List" ); } //If we got this far, something failed, redisplay form //parent categories model.ParentGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } }; if (model.ParentGroupId > 0) { var parentCategory = _articleService.GetArticleGroupById(model.ParentGroupId); if (parentCategory != null && !parentCategory.Deleted) model.ParentGroups.Add(new DropDownItem { Text = parentCategory.GetFormattedBreadCrumb(_articleService), Value = parentCategory.Id.ToString() }); else model.ParentGroupId = 0; } //Stores PrepareStoresMappingModel(model, articleGroup, true); return View(model); }
public ActionResult Create(ArticleGroupModel model, bool continueEditing) { if (ModelState.IsValid) { var articleGroup = model.ToEntity(); articleGroup.CreatedOnUtc = DateTime.UtcNow; articleGroup.UpdatedOnUtc = DateTime.UtcNow; _articleService.InsertArticleGroup(articleGroup); //search engine name model.SeName = articleGroup.ValidateSeName(model.SeName, articleGroup.Name, true); _urlRecordService.SaveSlug(articleGroup, model.SeName, 0); //locales UpdateLocales(articleGroup, model); _articleService.UpdateArticleGroup(articleGroup); //update picture seo file name UpdatePictureSeoNames(articleGroup); //Stores SaveStoreMappings(articleGroup, model); //activity log _customerActivityService.InsertActivity("AddNewArticleGroup", _localizationService.GetResource("ActivityLog.AddNewArticleGroup"), articleGroup.Name); SuccessNotification(_localizationService.GetResource("Admin.Plugins.ArticleManagement.ArticleGroups.Added")); return continueEditing ? RedirectToAction("Edit", new { id = articleGroup.Id }) : RedirectToAction("List"); } //parent categories model.ParentGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } }; if (model.ParentGroupId > 0) { var parentArticleGroup = _articleService.GetArticleGroupById(model.ParentGroupId); if (parentArticleGroup != null && !parentArticleGroup.Deleted) model.ParentGroups.Add(new DropDownItem { Text = parentArticleGroup.GetFormattedBreadCrumb(_articleService), Value = parentArticleGroup.Id.ToString() }); else model.ParentGroupId = 0; } //Stores PrepareStoresMappingModel(model, null, true); return View(model); }