Beispiel #1
0
        public IActionResult Groups(int?id)
        {
            var groups = _groupHandler.GetAll();

            ViewBag.Groups = groups;
            if (id.HasValue)/* in brackets && groups.Any(x=>x.Id == id)*/
            {
                var            activeGroup  = groups.FirstOrDefault(g => g.Id == id);
                var            users        = _usersInGroupHandler.GetUsersByGroup(id.Value);
                var            numberUsers  = _groupHandler.GetNumberUsersInGroup(id.Value);
                var            user         = _userManager.GetUserId(User);
                var            userName     = _userManager.GetUserName(User);
                List <AppUser> usersInGroup = new List <AppUser>();
                foreach (var u in users)
                {
                    var userInGroupId = _usersInGroupHandler.GetId(u);
                    var user1         = _userManager.Users.FirstOrDefault(k => k.Id == userInGroupId);
                    usersInGroup.Add(user1);
                }
                var userInGroup = _usersInGroupHandler.GetUserInGroup(activeGroup.Id, user);
                ViewBag.Group    = activeGroup.GroupName;
                ViewBag.GroupId  = activeGroup.Id;
                ViewBag.userName = _userManager.GetUserName(User);
                //ViewBag.Users = users;
                ViewBag.numberUsers  = numberUsers;
                ViewBag.usersInGroup = usersInGroup;
                ViewBag.userInGroup  = userInGroup;
            }

            else
            {
                ModelState.AddModelError("error", "Group not found!");
            }

            return(View(_userManager.Users.ToList()));
        }