示例#1
0
        public async Task <ActionResult> OnGet()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }
            try
            {
                var user = await _userManager.GetUserAsync(User);

                DefaultUserGroupID = await _siteData.GetDefaultUserGroupID(user.Id.ToString());

                if (DefaultUserGroupID == 0)
                {
                    if (HttpContext.Session.GetInt32("UserGroupID") == null)
                    {
                        UserGroups = await _siteData.GetUserGroups(user.Id.ToString());

                        int OwnUserGroupID = await _siteData.GetUserOwnGroup(user.Id.ToString());

                        for (int i = 0; i < UserGroups.Count(); i++)
                        {
                            if (OwnUserGroupID != UserGroups[i].UserGroupID)
                            {
                                return(RedirectToPage("WhichGroup"));
                            }
                            else
                            {
                                DefaultUserGroupID = OwnUserGroupID;
                                PotAccess          = await _siteData.GetPotAccess(user.Id.ToString(), DefaultUserGroupID);
                            }
                        }
                    }
                    else
                    {
                        CurrentUserGroupID = HttpContext.Session.GetInt32("UserGroupID");
                        DefaultUserGroupID = CurrentUserGroupID;
                        PotAccess          = await _siteData.GetPotAccess(user.Id.ToString(), CurrentUserGroupID);

                        return(Page());
                    }
                }
                PotAccess = await _siteData.GetPotAccess(user.Id.ToString(), DefaultUserGroupID);

                HttpContext.Session.SetInt32("UserGroupID", DefaultUserGroupID.Value);
                return(Page());
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }