public async Task <IActionResult> GetAliveAsync([FromQuery] DragonFilterApiModel filterModel)
        {
            try
            {
                var models = await _service.GetAliveAsync(filterModel);

                return(Ok(models));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
예제 #2
0
        public Task <IEnumerable <DragonEntity> > GetByFilter(DragonFilterApiModel model)
        {
            IQueryable <DragonEntity> entities = _repository.Table
                                                 .Where(e => String.IsNullOrEmpty(model.Name) || e.Name.StartsWith(model.Name))
                                                 .Where(e => !model.MinHp.HasValue || e.Hp > model.MinHp.Value)
                                                 .Where(e => !model.MaxHp.HasValue || e.Hp < model.MaxHp.Value)
                                                 .Where(e => !model.MinCurrentHp.HasValue || e.CurrentHp > model.MinCurrentHp.Value)
                                                 .Where(e => !model.MaxCurrentHp.HasValue || e.CurrentHp < model.MaxCurrentHp.Value)
                                                 .Where(e => e.DragonState == DragonStateEnum.IsAlive)
                                                 .OrderBy(e => e.Name)
                                                 .GetRange(model);

            return(Task.FromResult <IEnumerable <DragonEntity> >(entities));
        }
예제 #3
0
        public async Task <IEnumerable <DragonGetMinApiModel> > GetAliveAsync(DragonFilterApiModel filterModel)
        {
            IEnumerable <DragonEntity> entities;

            if (filterModel?.OptionFilter == false)
            {
                entities = await _repository.GetAlive(filterModel);
            }
            else
            {
                entities = await _repository.GetByFilter(filterModel);
            }

            return(_dataAdapter.Parse <DragonEntity, DragonGetMinApiModel>(entities));
        }