public async Task <JoinClubRequest> ApproveJoinClubRequest(string requestId, int requestType) { JoinClubRequest request = await this.dbContext.JoinClubRequests .FirstOrDefaultAsync(x => x.Id == requestId); if (requestType == 1) { UserClub userClub = new UserClub() { Club = request.Club, User = request.User, ClubId = request.ClubId, UserId = request.UserId }; await this.dbContext.UserClubs.AddAsync(userClub); request.RequestType = RequestType.Approved; } else if (requestType == 2) { request.RequestType = RequestType.Removed; } await this.dbContext.SaveChangesAsync(); return(request); }
public async Task <JoinClubRequest> CreateJoinRequestClub(string clubId, User user) { Club club = await this.clubService.GetClubById(clubId); JoinClubRequest joinClubRequest = new JoinClubRequest() { ClubId = clubId, Club = club, User = user, UserId = user.Id }; bool anyPreviousRequest = await this.dbContext.JoinClubRequests.AnyAsync(x => x.ClubId == clubId && x.UserId == user.Id && x.RequestType == RequestType.Pending); if (anyPreviousRequest) { return(null); } await this.dbContext.JoinClubRequests.AddAsync(joinClubRequest); await this.dbContext.SaveChangesAsync(); return(joinClubRequest); }
public async Task <JoinClubRequest> DeleteJoinClubRequest(string requestId) { JoinClubRequest request = await this.dbContext.JoinClubRequests .FirstOrDefaultAsync(x => x.Id == requestId); this.dbContext.JoinClubRequests.Remove(request); await this.dbContext.SaveChangesAsync(); return(request); }
public async Task <IActionResult> JoinClub(string id) { User user = await this.userManager.GetUserAsync(HttpContext.User); JoinClubRequest request = await this.requestService.CreateJoinRequestClub(id, user); if (request != null) { await this.notificationService.CreateNotification($"Успешно подадохте заявка за присъединяване към клуб - {request.Club.Name}. Вашата заявка очаква одобрение от администратор.", $"/Club/Details/{id}", request.User.Id); } return(this.Redirect($"/Club/Details/{id}")); }