public async Task <IActionResult> AddTournamentAsync(TournamentContractModel model) { try { //Check for current user and not from the model var currentUser = await GetCurrentUser(); //set current userId model.UserId = currentUser.Id; //Testing //model.UserId = model.UserId; //TODO: Get id of default point sytem. if (model.TournamentPointSystem.DefaultPointSystem == true) { model.TournamentPointSystem.TournamentPointSystemId = 1; } else { model.TournamentPointSystem.TournamentPointSystemId = await tournamentRepo.CreateSubmittedPointSystem(model.TournamentPointSystem); } // Create teamstatsId for the team return(await tournamentRepo.AddTournamentAsync(model)); } catch (Exception) { //log?? return(BadRequest()); } }
/// <summary> /// Add a new Team to the Team table. /// </summary> /// <param name="id"></param> /// <returns>Ok(Status code:200 if updated) else BadRequest(Status code: 400 if not updated)</returns> public async Task <IActionResult> AddTournamentAsync(TournamentContractModel model) { try { this.StartTransaction(); var newModel = new { Name = model.Name, Description = model.Description, SportId = model.Sport.SportId, TournamentTypeId = model.TournamentType.TournamentTypeId, TournamentPointSystemId = model.TournamentPointSystem.TournamentPointSystemId, UserId = model.UserId }; string insertQuery = @"INSERT INTO [dbo].[Tournament]([Name], [Description], [SportId], [TournamentTypeId], [TournamentPointSystemId], [UserId]) VALUES (@Name, @Description, @SportId, @TournamentTypeId, @TournamentPointSystemId, @UserId)"; // save the team model var rowsAffected = await this.SaveDataInTransactionUsingQueryAsync(insertQuery, newModel); this.CommitTransaction(); // if rows affected (item created) if (rowsAffected > 0) { return(new OkResult()); } else { return(new BadRequestResult()); } } catch (Exception ex) { this.RollbackTransaction(); // rollback & close //return false; ?? throw; } }
public async Task <IActionResult> UpdateTournamentAsync(TournamentContractModel TournamentModel) { try { var UserIdOfTeam = await tournamentRepo.GetAssociatedUserIdForTournamentAsync(TournamentModel.TournamentId); // Check if the corresponding tournament is of that user or is admin if (await CheckIfAuthorized(await GetCurrentUser(), UserIdOfTeam) != false) { // Create teamstatsId for the team return(await tournamentRepo.UpdateTournamentAsync(TournamentModel)); } //not authorized?? or not found?? return(NotFound()); } catch (Exception) { //log?? return(BadRequest()); } }
/// <summary> /// Update tournament data /// </summary> /// <param name="model">TournamentContractModel</param> /// <returns>Ok(Status code:200 if updated) else BadRequest(Status code: 400 if not updated)</returns> public async Task <IActionResult> UpdateTournamentAsync(TournamentContractModel model) { try { this.StartTransaction(); var newModel = new { TournamentId = model.TournamentId, Name = model.Name, Description = model.Description, SportId = model.Sport.SportId, TournamentTypeId = model.TournamentType.TournamentTypeId, TournamentPointSystemId = model.TournamentPointSystem.TournamentPointSystemId }; string updateQuery = @"UPDATE [dbo].[Tournament] SET Name=@Name, Description=@Description, SportId=@SportId, TournamentTypeId=@TournamentTypeId, TournamentPointSystemId=@TournamentPointSystemId WHERE TournamentId=@TournamentId"; var rowsAffected = await this.SaveDataInTransactionUsingQueryAsync(updateQuery, newModel); this.CommitTransaction(); // if rows affected (item created) if (rowsAffected > 0) { return(new OkResult()); } else { return(new BadRequestResult()); } } catch (Exception s) { this.RollbackTransaction(); // rollback & close throw; } }