/// <summary> /// Attempts to create a new spell. /// /// ROUTE /// `api/spell/` /// /// REQUEST BODY /// { /// "name": `string`, /// "level": `int`, /// "school": `string`, /// "castingTime": `string`, /// "range": `string`, /// "verbal": `bool`, /// "somatic": `bool`, /// "materials": `string`, /// "duration": `string`, /// "ritual": `bool`, /// "description": `string` /// } /// /// RESPONSE BODY /// { /// "success": `bool`, /// "message": `string`, /// "spell": { /// "id": `int`, /// "name": `string`, /// "level": `int`, /// "school": `string`, /// "castingTime": `string`, /// "range": `string`, /// "verbal": `bool`, /// "somatic": `bool`, /// "materials": `string`, /// "duration": `string`, /// "ritual": `bool`, /// "description": `string` /// } /// } /// </summary> /// <param name="id">The ID of the spell.</param> /// <returns>The response body.</returns> public async Task <SpellCreateResponse> Post(SpellCreateRequest request) { var response = new SpellCreateResponse() { Success = false }; if (ModelState.IsValid) { SchoolOfMagic school; if (Enum.TryParse(request.School, out school)) { var spell = new Spell() { Name = request.Name, Level = request.Level.Value, School = school, CastingTime = request.CastingTime, Range = request.Range, Verbal = request.Verbal.Value, Somatic = request.Somatic.Value, Materials = request.Materials, Duration = request.Duration, Ritual = request.Ritual.Value, Description = request.Description }; int?spellId = await _spellRepo.AddAsync(spell); if (spellId.HasValue) { response.Success = true; response.Message = "Spell successfully created."; response.Spell = spell.GetInfo(); return(response); } } } response.Message = "Unable to create spell. Please check parameter values."; return(response); }