public IActionResult EditBug(int BugId)
        {
            MyBugEditViewModel myBugEditViewModel = new MyBugEditViewModel();

            IEnumerable <Bug> bugs = BugRepository.GetBug(BugId);
            var bug = bugs.First();

            myBugEditViewModel.bug = bug;


            List <Category> categories = CategoryRepository.GetAllCategory().ToList();

            ViewBag.ListOfCategory      = categories;
            myBugEditViewModel.category = bug.SubCat.Cat;

            List <SubCategory> subCategories = SubCategoryRepository.GetAllSubCategory().ToList();

            subCategories                  = (from subCategory in subCategories where subCategory.CategoryId == bug.SubCat.Cat.CatID select subCategory).ToList();
            ViewBag.ListOfSubCategory      = subCategories;
            myBugEditViewModel.subCategory = bug.SubCat;

            var id = userManager.GetUserId(User);
            IEnumerable <Bug> bugsList = BugRepository.GetAllBugsOfUser(id);

            myBugEditViewModel.bugs = bugsList;
            return(View(myBugEditViewModel));
        }
        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));
        }
        public IActionResult EditBug(int BugId, MyBugEditViewModel myBugEditViewModel)
        {
            if (ModelState.IsValid)
            {
                var SubCategoryID = HttpContext.Request.Form["SubCatId"].ToString();
                if (SubCategoryID == "0")
                {
                    ModelState.AddModelError("", "Select SubCategory");
                    return(View(myBugEditViewModel));
                }

                Bug newBug = myBugEditViewModel.bug;
                newBug.SubCategoryId = Int32.Parse(SubCategoryID);

                BugRepository.UpdateBug(newBug);
                return(RedirectToAction("Index"));
            }
            IEnumerable <Bug> bugs = BugRepository.GetBug(BugId);
            var bug = bugs.First();

            myBugEditViewModel.bug = bug;

            List <Category> categories = CategoryRepository.GetAllCategory().ToList();

            ViewBag.ListOfCategory      = categories;
            myBugEditViewModel.category = bug.SubCat.Cat;

            List <SubCategory> subCategories = SubCategoryRepository.GetAllSubCategory().ToList();

            subCategories                  = (from subCategory in subCategories where subCategory.CategoryId == bug.SubCat.Cat.CatID select subCategory).ToList();
            ViewBag.ListOfSubCategory      = subCategories;
            myBugEditViewModel.subCategory = bug.SubCat;

            var id = userManager.GetUserId(User);
            IEnumerable <Bug> bugsList = BugRepository.GetAllBugsOfUser(id);

            myBugEditViewModel.bugs = bugsList;
            return(View(myBugEditViewModel));
        }