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); } }
//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; } }
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); }
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); }
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); }