Main.Controllers.CategoriesController.Index C# (CSharp) Method

Index() public method

public Index ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
        public ActionResult Index()
        {
            ViewBag.UserID = User.Identity.Name;

            var currentUser = db.AspNetUsers.Where(u => u.Email == User.Identity.Name);

            if (currentUser.Count() == 0 || currentUser.First().Role != 1) {
                return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
            }

            return View(db.Categories.ToList());
        }

Usage Example

 public void testIndex()
 {
     CategoriesController categoriesController = new CategoriesController();
     ActionResult index = categoriesController.Index();
 }