Beispiel #1
0
        //lists out the accounts of the site users on the system
        public ActionResult UserAccounts()
        {
            //prevents users from accessing the page if they are not logged in
            if (userSession.LoggedIn == false)
            {
                return(Content("You are not logged in ! Please login to view this page"));
            }

            //prevents non admin users from viewing the page
            Account account   = userSession.CurrentUser;
            var     adminUser = accountPermissionDAO.FetchByEmail(account.email);

            if (adminUser == null)
            {
                return(Content("This page is restricted to super admin users."));
            }

            //calls method in repository that lists out all the accounts in the system
            IEnumerable <Account> accounts = accountDAO.FetchAllUserAccounts();

            //returns a list of only non admin accounts
            List <Account> userAccounts = new List <Account>();

            foreach (Account a in accounts)
            {
                var adminAccount = accountPermissionDAO.FetchByEmail(a.email);
                if (adminAccount == null)
                {
                    userAccounts.Add(a);
                }
            }

            List <Account> result = userAccounts.ToList();

            //wraps list into model
            BeautySNS.Admin.Models.Accounts.IndexViewModel model = new BeautySNS.Admin.Models.Accounts.IndexViewModel(result);

            model.adminUser         = true;
            model.userSession       = userSession.LoggedIn;
            model.loggedInAccount   = account;
            model.loggedInAccountID = account.accountID;
            model.permissionType    = adminUser.Permission.name;
            return(View(model));
        }