public ActionResult Add(CategoryAddViewModel category) { if (!ModelState.IsValid) { category.Categories = this.categories.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ParentCategoryId.ToString() }); return this.View(category); } var categoryToAdd = new Category() { Name = category.Name, ParentCategoryId = category.ParentCategoryId == null ? null : (int?)int.Parse(category.ParentCategoryId) }; using (var unitOfWork = this.unitOfWork()) { this.categories.Add(categoryToAdd); unitOfWork.Commit(); } return this.RedirectToAction("Details/" + categoryToAdd.Id, "Categories"); }
public ActionResult Add() { var model = new CategoryAddViewModel(); model.Categories = this.categories.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ParentCategoryId.ToString() }); return this.View(model); }