public async Task <IActionResult> Edit([FromBody] RoundModel model) { if (!ModelState.IsValid) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid round edit request", GetModelStateMessages())); } if (!model.Id.HasValue) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid round edit request", "Please send a valid round id to edit a round")); } var round = await _dataStore.GetAsync <Round>(model.Id.Value); if (round == null) { return(ReturnError(StatusCodes.Status404NotFound, "Invalid round edit request", $"Round {model.Id} not found")); } if (!round.CanUpdateRound(User)) { return(ReturnError(StatusCodes.Status403Forbidden, "Invalid had round request", $"You are not allowed to update this round")); } round = await model.UpdateRound(round, _dataStore); if (!model.IsRoundValid || round == null) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid round edit request", model.AllValidationMessages)); } round = await _dataStore.UpdateAsync(round); return(Accepted(RoundSummaryModel.FromRound(round))); }
public void FromRound_ReturnsValidModel() { var round = DummyRound(); var res = RoundSummaryModel.FromRound(round); Assert.Equal(2, res.UsersInRound.Count); Assert.Equal(round.RoundDescription, res.RoundDescription); }
public async Task <IActionResult> Get([FromRoute] Guid id) { var round = await _dataStore.GetAsync <Round>(id); if (!round.CanUpdateRound(User)) { return(ReturnError(StatusCodes.Status403Forbidden, "Invalid had round request", "You are not to access this round")); } return(Ok(RoundSummaryModel.FromRound(round))); }
public async Task <IActionResult> New([FromBody] RoundModel model) { if (!ModelState.IsValid) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid round creation request", GetModelStateMessages())); } var round = await model.CreateRoundFromModel(_dataStore); if (!model.IsRoundValid) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid round creation request", model.AllValidationMessages)); } await _dataStore.CreateAsync(round); return(Accepted(RoundSummaryModel.FromRound(round))); }
public async Task <IActionResult> HadRound([FromBody] HadRoundModel model) { if (!ModelState.IsValid) { return(ReturnError(StatusCodes.Status400BadRequest, "Invalid had round request", GetModelStateMessages())); } var round = await _dataStore.GetAsync <Round>(model.Id); if (round == null) { return(ReturnError(StatusCodes.Status404NotFound, "Invalid had round request", $"Round {model.Id} not found")); } if (!round.CanUpdateRound(User)) { return(ReturnError(StatusCodes.Status403Forbidden, "Invalid had round request", $"You are not allowed to update this round")); } await _roundService.UpdateExistingRoundAsync(round, _dataStore, model.UserGettingRound, model.RoundNotes); return(Ok(RoundSummaryModel.FromRound(round))); }