public ActionResult Create([Bind(Include = "SubcategoryId,Name,CategoryId")] NewSubcategoryViewModel subcategoryToCreate) { if (ModelState.IsValid) { _subcategoryService.Create(subcategoryToCreate); return(RedirectToAction("Index", "Categories")); } //ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", subcategory.CategoryId); return(View(subcategoryToCreate)); }
public Guid Create(NewSubcategoryViewModel model) { Subcategory newSubcategory = new Subcategory() { SubcategoryId = Guid.NewGuid(), Name = model.Name, CategoryId = model.CategoryId }; _dbContext.Subcategories.Add(newSubcategory); _dbContext.SaveChanges(); return(newSubcategory.SubcategoryId); }
// GET: Subcategories/Create public ActionResult Create(Guid?categoryId) { if (categoryId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Category currentCategory = _categoryService.GetCategoryById(categoryId); if (currentCategory == null) { return(HttpNotFound()); } NewSubcategoryViewModel model = new NewSubcategoryViewModel() { CategoryName = currentCategory.Name }; return(View(model)); }