private void LoadViewBagItems() { var enumHelper = new EnumerationHelper(); var sites = enumHelper.GetSites(); var allRoles = enumHelper.GetRoles(); var roles = new List <SelectListItem>(); if (User != null) { var name = global::System.Web.Security.Membership.GetUser(User.Identity.Name); if (name != null) { using (var adminUow = DependencyResolver.Current.GetService <IAdminUnitOfWork>()) { var user = adminUow.UserRepository.GetUser(new Guid(name.ProviderUserKey.ToString())); var appUser = user.AppUsers.FirstOrDefault(); if (appUser != null && (appUser.SiteId > 0 || !User.IsInRole(GlobalVariables.RoleSystemAdmin))) { sites = sites.Where(s => s.Value == appUser.SiteId.ToString(CultureInfo.InvariantCulture)); roles.AddRange(allRoles.Where(r => r.Text != GlobalVariables.RoleSystemAdmin)); } else { roles.AddRange(allRoles); } } } } ViewBag.Sites = sites; ViewBag.Roles = roles; }