public async Task <IActionResult> Edit(TeamTournament teamTournament) { if (ModelState.IsValid) { // Get previous object var tt = await db.TeamTournament.SingleAsync(x => x.Id == teamTournament.Id); tt.Name = teamTournament.Name; await db.SaveChangesAsync(Context.RequestAborted); return(RedirectToAction("Manage", "Clan")); } return(View(teamTournament)); }
public async Task <IActionResult> RegisterClan(int id) { var tournament = await db.Tournaments.FirstOrDefaultAsync(t => t.Id == id); if (tournament == null) { return(new HttpStatusCodeResult(404)); } // Get current user's clan details var currentUser = await db.Users.Include(x => x.Clan).SingleAsync(x => x.UserName == User.Identity.Name); // Make sure the user is part of a clan if (currentUser.Clan == null) { ViewBag.Error = "You must be part of a clan to do this operation"; return(RedirectToAction("Index")); } // Make sure this user is the clan owner if (currentUser.Clan.OwnerUserId != currentUser.Id) { ViewBag.Error = "You must be the leader of your clan to register in a tournament"; return(RedirectToAction("Index")); } var teamTournament = new TeamTournament { TournamentId = id, ClanId = (int)currentUser.ClanId, Name = currentUser.Clan.Name }; await db.AddAsync(teamTournament); await db.SaveChangesAsync(); return(RedirectToAction("Manage", "Clan")); }
public async Task <bool> TeamJoin(int tournamentId, int teamId) { var tournamentInfo = await this.GetTournamentInfo(tournamentId, teamId); if (tournamentInfo.TeamIsInTournament || tournamentInfo == null) { //TODO ADD MESSAGE!! return(false); } var teamInTournament = new TeamTournament { TeamId = teamId, TournamentId = tournamentId }; this.db.Add(teamInTournament); await this.db.SaveChangesAsync(); return(true); }