public async Task <IActionResult> PutCharacterData(string id, CharacterData characterData) { //Console.WriteLine("PUT Character: " + characterData.Health.HitPointsCurrent.ToString()); if (id != characterData.Name) { return(BadRequest()); } characterData.AdjustRollMethod(characterData.RollMethod != null ? characterData.RollMethod : "default"); characterData.ApplyBonuses(); _context.Update(characterData); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharacterDataExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <CharacterData> > PostCharacterData(CharacterData characterData) { if (CharacterDataExists(characterData.Name)) { return(Conflict()); } characterData.AdjustRollMethod(characterData.RollMethod != null ? characterData.RollMethod : "default"); characterData.ApplyBonuses(); _context.CharacterData.Add(characterData); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CharacterDataExists(characterData.Name)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetCharacterData", new { id = characterData.Name }, characterData)); }