示例#1
0
        public ActionResult Index()
        {
            using (var db = ApplicationDbContext.Create())
            {
                if (!User.Identity.IsAuthenticated)
                {
                    throw new HttpException(403, "Forbidden");
                }

                var thisUser = db.Users.Where(x => x.UserName == User.Identity.Name)
                               .Include(x => x.Organizations)
                               .FirstOrDefault();


                List <Organization> orgs = OrganizationHelper.GetAvailableOrganizationsForUser(db, User);

                var model = new OrganizationIndexModel();
                model.IsSiteAdministrator = thisUser.IsAdministrator;

                foreach (var org in orgs)
                {
                    var orgModel = new OrganizationInListModel()
                    {
                        Organization        = org,
                        CanUserAssignRights = OrganizationHelper.DoesUserHaveRight(db, User, org.Id, Right.CanAssignRights)
                    };

                    model.Organizations.Add(orgModel);
                }

                return(View(model));
            }
        }