public ActionResult Create(string topic) { Resource Resource = new Resource(); Resource.Topic = topic; ViewData["categories"] = new SelectList(_categoryRepository.FindByType("resource"), "ID", "Name", _categoryRepository.GetByIndex(0)); return View(Resource); }
public ActionResult Create(Resource Resource, int categoryId) { if (ModelState.IsValid) { Resource.Category = _categoryRepository.GetById(categoryId); UpdateModel<Resource>(Resource); _resourceRepository.Add(Resource); UnitOfWork.Save(); return RedirectToAction("Index", "Resource"); } return View(Resource); }
public ActionResult Edit(int id, Resource Resource, int categoryId) { var ResourceInDb = _resourceRepository.GetById(id); ResourceInDb.Category = _categoryRepository.GetById(categoryId); if (TryUpdateModel(ResourceInDb)) { UnitOfWork.Save(); return RedirectToAction("Index", "Resource"); } return View(Resource); }