Badges.Controllers.HomeController.Index C# (CSharp) Method

Index() private method

private Index ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
        public ActionResult Index()
        {
            var user =
            RepositoryFactory.UserRepository.Queryable.SingleOrDefault(x => x.Identifier == CurrentUser.Identity.Name);

            if (user == null)
            {
                return RedirectToAction("Create", "Profile");
            }

            var roles = user.Roles.ToList();

            if (roles.Any(x => x.Id == RoleNames.Student))
            {
                return RedirectToAction("Index", "Student");
            }

            if (roles.Any(x => x.Id == RoleNames.Instructor))
            {
                return RedirectToAction("Index", "Instructor");
            }

            if (roles.Any(x => x.Id == RoleNames.Administrator))
            {
                return RedirectToAction("Index", "Landing", new { area = "Admin" });
            }

            return new HttpUnauthorizedResult();
        }

Usage Example

Example #1
0
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController(null);

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.AreEqual("Modify this template to jump-start your ASP.NET MVC application.", result.ViewBag.Message);
        }