public IActionResult EditCategory(string objectId) { Category result = null; //load category if available if (string.IsNullOrEmpty(objectId) == false) { result = _categoryService.GetCategoryById(new MongoDB.Bson.ObjectId(objectId)); } CategoryViewModel viewModel; if (result != null) { viewModel = new CategoryViewModel() { Active = result.Active, Name = result.Name, ObjectId = result.Id.ToString() }; } else { viewModel = new CategoryViewModel(); } return View(viewModel); }
public async Task<IActionResult> EditCategory(CategoryViewModel model) { if (ModelState.IsValid) { Category result = null; //load category if available if (string.IsNullOrEmpty(model.ObjectId) == false) { result = _categoryService.GetCategoryById(new MongoDB.Bson.ObjectId(model.ObjectId)); } if (result == null) result = new Category(); result.Name = model.Name; result.Active = model.Active; await _categoryService.SaveCategory(result); return RedirectToAction("CategorySetup"); } return View(); }