public IActionResult Index() { MyBugAddViewModel myBugAddViewModel = new MyBugAddViewModel(); var id = userManager.GetUserId(User); IEnumerable <Bug> bugs = BugRepository.GetAllBugsOfUser(id); List <Category> categories = CategoryRepository.GetAllCategory().ToList(); categories = (from category in categories select category).ToList(); categories.Insert(0, new Category { CatID = 0, CatName = "Select Category", }); ViewBag.ListOfCategory = categories; myBugAddViewModel.bugs = bugs; return(View(myBugAddViewModel)); }
public IActionResult Index(MyBugAddViewModel myBugAddViewModel) { if (ModelState.IsValid) { if (myBugAddViewModel.category.CatID == 0) { ModelState.AddModelError("", "Select Category"); return(View(myBugAddViewModel)); } var SubCategoryID = HttpContext.Request.Form["SubCatId"].ToString(); if (SubCategoryID == "0") { ModelState.AddModelError("", "Select SubCategory"); return(View(myBugAddViewModel)); } Bug bug = myBugAddViewModel.bug; bug.SubCategoryId = Int32.Parse(SubCategoryID); bug.ApplicationUserId = userManager.GetUserId(User); bug.IssueDate = DateTime.Now; BugRepository.AddBug(bug); return(RedirectToAction("Index")); } var id = userManager.GetUserId(User); IEnumerable <Bug> bugs = BugRepository.GetAllBugsOfUser(id); myBugAddViewModel.bugs = bugs; List <Category> categories = CategoryRepository.GetAllCategory().ToList(); categories = (from category in categories select category).ToList(); categories.Insert(0, new Category { CatID = 0, CatName = "Select Category", }); ViewBag.ListOfCategory = categories; return(View(myBugAddViewModel)); }