public ActionResult Create(CategoryCreateEditModel model) { if (ModelState.IsValid) { Guid? parent = null; if (model.ParentCategoryId != null) { Guid p; if (Guid.TryParse(model.ParentCategoryId, out p)) { parent = p; } } BllCategory cat = new BllCategory() { Id = model.Id, Name = model.CategoryName.Trim(), Description = model.Description, DateCreated = DateTime.UtcNow, ParentCategoryId = parent }; _categoryService.Add(cat); return RedirectToAction("Index"); } return View(model); }
public ActionResult Create() { var categoriesforDropDown = GetCategoriesForDropDown(); ViewBag.Categories = categoriesforDropDown; var model = new CategoryCreateEditModel() { Id = Guid.NewGuid(), CategoryName = string.Empty, Description = string.Empty, ParentCategoryId = null }; return View(model); }
public ActionResult Edit(CategoryCreateEditModel model) { if (ModelState.IsValid) { var category = _categoryService.Get(model.Id); category.Description = model.Description.Trim(); category.Name = model.CategoryName.Trim(); category.ParentCategoryId = null; if (model.ParentCategoryId != null) { Guid parent; Guid.TryParse(model.ParentCategoryId, out parent); category.ParentCategoryId = parent; } _categoryService.Update(category); return RedirectToAction("Index"); } return View(model); }