Exemplo n.º 1
0
        public ActionResult List()
        {
            var model = new List <KeyValuePair <string, string> >();

            // sysadmin can see all system users
            if (Roles.IsUserInRole("sysadmin"))
            {
                foreach (var user in ModRepository.GetAllUsers())
                {
                    var sb = new StringBuilder();
                    foreach (var acc in user.Accounts.Select(a => a.Name))
                    {
                        sb.Append(acc + ", ");
                    }
                    model.Add(new KeyValuePair <string, string>(
                                  sb.ToString().TrimEnd(", ".ToCharArray()),
                                  user.UserName));
                }
            }
            else if (Roles.IsUserInRole("administrators"))
            {
                var userId   = (Guid)Membership.GetUser().ProviderUserKey;
                var accounts = ModRepository.GetUserAccounts(userId);

                foreach (var acct in accounts)
                {
                    foreach (var user in ModRepository.GetAccountUsers(acct.Id))
                    {
                        model.Add(new KeyValuePair <string, string>(
                                      acct.Name,
                                      user.UserName));
                    }
                }
            }

            return(View(model));
        }