Exemple #1
0
        /// <summary>
        /// Retrieves a list of spells. Results can be filtered by passing in
        /// parameters through the query string.
        ///
        /// ROUTE
        /// `api/spell`
        ///
        /// RESPONSE BODY
        /// {
        ///     "spells": [
        ///         {
        ///             "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>
        /// <returns>The response body.</returns>
        public async Task <SpellListResponse> Get([FromUri] SpellListFilter filter)
        {
            var spells = await _spellRepo.ListAsync(filter);

            var response = new SpellListResponse()
            {
                Spells = spells.Select(s => s.GetInfo()).ToList()
            };

            return(response);
        }
        public Task <List <Spell> > ListAsync(SpellListFilter filter)
        {
            var spells = _context.Spells
                         .Where(s =>
                                (!filter.Level.HasValue || filter.Level.Value == s.Level) &&
                                (!filter.School.HasValue || filter.School.Value == s.School) &&
                                (filter.Name == null || s.Name.Contains(filter.Name))
                                )
                         .ToListAsync();

            return(spells);
        }