public async Task <GetPagedSpellsCommand> ExecuteActionAsync(GetPagedSpellsCommand command)
        {
            int skip = (int)(command.PageSize * (command.PageNumber - 1));
            int take = (int)(command.PageSize);

            var result = await Context.GetAsync(skip, take, s => new SpellResponseDto()
            {
                Id           = s.Id,
                BaseDamage   = s.BaseDamage,
                BaseManaCost = s.BaseManaCost,
                Element      = s.Element.ToString(),
                Name         = s.Name,
                Rules        = s.Rules.Select(r => new SpellRuleRequestDto()
                {
                    Id               = r.Id,
                    Operator         = (byte)r.Operator,
                    WeatherCondition = (byte)r.WeatherCondition,
                    Value            = r.Value,
                })
            });

            if (result is null)
            {
                return(command);
            }

            command.Result = result;
            await UpdatePaginationInfoAsync(command, skip, take);

            return(command);
        }
예제 #2
0
        /// <summary>
        /// Attempts to delete a spell with a given id.
        ///
        /// ROUTE
        /// `api/spell/{id}`
        ///
        /// RESPONSE BODY
        /// {
        ///     "success": `bool`,
        ///     "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 <SpellDeleteResponse> Delete(int id)
        {
            // Query to get spell information. Maybe this isn't
            // needed and we can just return a status code.
            var spell = await _spellRepo.GetAsync(id);

            var response = new SpellDeleteResponse()
            {
                Success = false
            };

            if (await _spellRepo.DeleteAsync(id))
            {
                response.Success = true;
                response.Spell   = spell.GetInfo();
            }
            return(response);
        }
예제 #3
0
        public async Task <bool> AddSpellAsync(int spellbookId, int spellId)
        {
            try
            {
                var spellbook = await GetAsync(spellbookId);

                var spell = await _spellRepo.GetAsync(spellId);

                if (spellbook.Spells.Contains(spell))
                {
                    return(false);
                }
                spellbook.Spells.Add(spell);
                _context.UpdateEntity(spellbook);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }