public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                return;
            }

            //TODO: temporary fix. IoC should resolve it automatically
            UserRepository = DependencyResolver.Current.GetService<IRepository<User, Guid>>();

            var viewResult = filterContext.Result as ViewResult;
            if (viewResult != null)
            {
                string currentUserEmail = filterContext.HttpContext.User.Identity.Name;
                User currentUser = UserRepository.GetOne(r => r.Email == currentUserEmail);
                if (currentUser != null)
                {
                    viewResult.ViewBag.Username = currentUser.Name;
                }
            }
        }
Example #2
0
 private static bool UserWithEmailExists(IRepository<User, Guid> userRepository, string userEmail)
 {
     return userRepository.GetOne(u => u.Email == userEmail) != null;
 }