Example #1
0
        public async Task <IActionResult> Edit(string id, ClubAdmin ClubAdmin)
        {
            var user = await _context.ClubAdmins.SingleOrDefaultAsync(c => c.Id == id);

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

            try
            {
                if (await _userManager.Users.SingleOrDefaultAsync(c => c.UserName == ClubAdmin.UserName) != null)
                {
                    return(NoContent());
                }
                user.UserName    = ClubAdmin.UserName;
                user.Email       = ClubAdmin.Email;
                user.FullName    = ClubAdmin.FullName;
                user.PhoneNumber = ClubAdmin.PhoneNumber;
                user.Gender      = ClubAdmin.Gender;
                await _userManager.UpdateAsync(user);

                return(Ok(user));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Example #2
0
        //POST : /api/ClubAdmin/Register
        public async Task <Object> PostApplicationUser(RegisterUserModel model)
        {
            var ClubAdmin = new ClubAdmin()
            {
                UserName    = model.UserName,
                Email       = model.Email,
                FullName    = model.FullName,
                PhoneNumber = model.PhoneNumber,
                IsActive    = false,
                Gender      = model.Gender
            };

            try
            {
                var result = await _userManager.CreateAsync(ClubAdmin, model.Password);

                await _userManager.AddToRoleAsync(ClubAdmin, "ClubAdmin");

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public async Task <ClubAdmin> RemoveClubAdmin(Club club, User user)
        {
            ClubAdmin clubAdmin = await this.dbContext.ClubAdmins
                                  .FirstOrDefaultAsync(x => x.User == user && x.Club == club);

            if (clubAdmin != null)
            {
                this.dbContext.ClubAdmins.Remove(clubAdmin);
            }

            await this.userManager.RemoveFromRoleAsync(user, UserRoles.ClubAdmin);

            await this.dbContext.SaveChangesAsync();

            return(clubAdmin);
        }
Example #4
0
        public async Task <ClubAdmin> AddClubAdmin(Club club, User user)
        {
            ClubAdmin newClubAdmin = new ClubAdmin()
            {
                Club = club,
                User = user,
            };

            var result = await dbContext.ClubAdmins.AddAsync(newClubAdmin);

            await this.userManager.AddToRoleAsync(user, UserRoles.ClubAdmin);

            await this.dbContext.SaveChangesAsync();

            return(result.Entity);
        }
Example #5
0
        public ClubAdmin AddClubAdmin(User newAdminUser, User adminUser, Club club)
        {
            if (!IsUserClubAdmin(adminUser, club))
            {
                throw new InvalidCredentialException($"That user with id '{adminUser.Id}' does not have premission to add new admins");
            }

            var clubAdmin = new ClubAdmin
            {
                UserId = newAdminUser.Id
            };

            var cadmin = _context.ClubAdmins.Add(clubAdmin);

            _context.Context.SaveChanges();
            return(cadmin);
        }