Beispiel #1
0
        public async Task <IActionResult> Add(string id, TeamConfigUsersViewModel teamConfigUsersVM)
        {
            if (ModelState.IsValid)
            {
                AdminAssignedToTeam adminAssignedToTeam = new AdminAssignedToTeam()
                {
                    ApplicationUserId = id,
                    TeamId            = teamConfigUsersVM.Team.Id,
                    ApplicationUser   = await _db.ApplicationUsers.FindAsync(id),
                    Team = await _db.Teams.FindAsync(teamConfigUsersVM.Team.Id)
                };


                foreach (var adminAssigned in _db.AdminAssignedToTeam)
                {
                    if (adminAssigned.ApplicationUserId == adminAssignedToTeam.ApplicationUserId && adminAssigned.TeamId == adminAssignedToTeam.TeamId)
                    {
                        return(RedirectToAction("Index", new { id = teamConfigUsersVM.Team.Id }));
                    }
                }


                await _db.AdminAssignedToTeam.AddAsync(adminAssignedToTeam);


                TempData["Msg"] = "Admin has been added successfully";

                await _db.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = teamConfigUsersVM.Team.Id }));
            }

            return(RedirectToAction("Index", "Team"));
        }
Beispiel #2
0
        //GET
        /// <summary>Provides a list of <see cref="ApplicationUser"/> objects assigned to the specified <see cref="Team"/></summary>
        /// <param name="id">The specified <see cref="Team"/> id.</param>
        public async Task <IActionResult> Index(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var team = await _db.Teams.FindAsync(id);

            if (team == null)
            {
                return(NotFound());
            }

            TeamConfigUsersViewModel teamConfigUsersVM = new TeamConfigUsersViewModel();

            teamConfigUsersVM.Team      = team;
            teamConfigUsersVM.AllAdmins = new List <ApplicationUser>();

            foreach (var user in _db.ApplicationUsers)
            {
                if (await _userManager.IsInRoleAsync(user, "Admin") || await _userManager.IsInRoleAsync(user, "SuperAdmin"))
                {
                    teamConfigUsersVM.AllAdmins.Add(user);
                }
            }

            teamConfigUsersVM.AdminsAssignedToTeam = new List <ApplicationUser>();
            foreach (var adminAssigned in _db.AdminAssignedToTeam)
            {
                foreach (var admin in teamConfigUsersVM.AllAdmins)
                {
                    if (adminAssigned.ApplicationUserId == admin.Id && adminAssigned.TeamId == teamConfigUsersVM.Team.Id)
                    {
                        teamConfigUsersVM.AdminsAssignedToTeam.Add(admin);
                    }
                }
            }



            return(View(teamConfigUsersVM));
        }