public async Task <ActionResult> Create([Bind(Include = "Language,Name,CategoryId")] CreateCodePoolViewModel codepoolViewModel) { if (ModelState.IsValid) { CodePool codePool = new CodePool() { Name = codepoolViewModel.Name, Language = codepoolViewModel.Language, Category = await db.Categories.FindAsync(codepoolViewModel.CategoryId) }; db.CodePools.Add(codePool); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(codepoolViewModel)); }
// GET: /CodePools/Create public async Task <ActionResult> Create(int?categoryId) { if (categoryId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Category category = await db.Categories.FindAsync(categoryId); if (category == null) { return(HttpNotFound()); } var createCodePoolViewModel = new CreateCodePoolViewModel() { CategoryId = category.Id }; return(View(createCodePoolViewModel)); }