public async Task <IActionResult> SetDevRanges(SetDevModel setDevModel) { if (setDevModel is null) { return(NotFound()); } var championship = await _champService.GetChampionshipById(setDevModel.ChampionshipId, true); // This if-structure makes it so that we are going to apply all those darn age dev ranges to the code! if (setDevModel.AgeValueKey.Count > 0) { // Calls the service method that validates and adds the ranges to the championship var errString = _champService.SetRangeToChampionship(championship, true, setDevModel.AgeValueKey, setDevModel.AgeMinDev, setDevModel.AgeMaxDev); // Uh oh, the returned string wasn't empty so this means something went wrong! Return to the view with an error message if (!string.IsNullOrEmpty(errString)) { return(RedirectToAction(nameof(SetDevRanges), new { id = setDevModel.ChampionshipId, statusmessage = $"Error at age: {errString}" })); } } // Applies the same process for the skill values if (setDevModel.SkillValueKey.Count > 0) { // Calls the service method that validates and adds the ranges to the championship var errString = _champService.SetRangeToChampionship(championship, false, setDevModel.SkillValueKey, setDevModel.SkillMinDev, setDevModel.SkillMaxDev); // Ruh roh, the returned string wasn't empty so this means something went wrong! Return to the view with an error message if (!string.IsNullOrEmpty(errString)) { return(RedirectToAction(nameof(SetDevRanges), new { id = setDevModel.ChampionshipId, statusmessage = $"Error at skill: {errString}" })); } } _champService.Update(championship); await Context.SaveChangesAsync(); return(RedirectToAction(nameof(SetDevRanges), new { id = setDevModel.ChampionshipId, statusmessage = "Dev ranges succesfully set!" })); }
public IActionResult Put(int id, [FromBody] ChampionshipDTO model) { model.ID = id; _championshipService.Update(model); return(Ok()); }