protected virtual void PrepareAllCategoriesModel(CategoryModel model) { if (model == null) throw new ArgumentNullException("model"); model.AvailableCategories.Add(new SelectListItem() { Text = "父分类", Value = "0" }); var permissions = _categoryService.GetAllCategory(); foreach (var p in permissions) { model.AvailableCategories.Add(new SelectListItem() { Text = _categoryService.GetFormattedBreadCrumb(p), Value = p.Id.ToString() }); } }
public ActionResult Create(CategoryModel model, bool continueEditing) { if (ModelState.IsValid) { var category = model.ToEntity(); category.CreatedOnDate = DateTime.Now; category.UpdatedOnDate = DateTime.Now; _categoryService.InsertCategory(category); SuccessNotification("添加成功"); return continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List"); } PrepareAllCategoriesModel(model); return View(model); }
public ActionResult Edit(CategoryModel model, bool continueEditing) { var category = _categoryService.GetCategoryById(model.Id); if (ModelState.IsValid) { int prevPictureId = category.PictureId; category = model.ToEntity(category); category.UpdatedOnDate = DateTime.Now; _categoryService.UpdateCategory(category); //图片处理, 删除旧图片 if (prevPictureId > 0 && prevPictureId != category.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } SuccessNotification("更新成功"); return continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List"); } PrepareAllCategoriesModel(model); return View(model); }
public ActionResult Create() { var model = new CategoryModel(); PrepareAllCategoriesModel(model); return View(model); }