public ActionResult <List <DamageDto> > GetDemageList(DamageSearchDto damageSearchDto) { try { int heroId = HeroService.GetLoggedInUserId(this); List <Hit> hits = _service.GetAll().Where(h => h.HeroId == heroId).ToList(); List <long> dragonIds = hits.Select(h => h.DragonId).ToList(); List <Dragon> dragons = _dragonService.GetAll().Where(d => dragonIds.Contains(d.Id)).ToList(); List <DamageDto> damageList = new List <DamageDto>(); foreach (long id in dragonIds) { List <Hit> _hits = hits.FindAll(h => h.Id == id).ToList(); List <int> dragonDamage = new List <int>(); foreach (Hit h in _hits) { dragonDamage.Add(h.Force); } damageList.Add( new DamageDto() { Damage = dragonDamage.Sum(), DragonName = dragons.Find(d => d.Id == id).Name } ); } switch (damageSearchDto.SearchParams) { case SearchParams.Name: { if (damageSearchDto.SearchType == SearchType.Greater) { damageList.Sort(SortService.SortByNameAsc); } else if (damageSearchDto.SearchType == SearchType.Lesser) { damageList.Sort(SortService.SortByNameDesc); } else { throw new SearchException(); } break; } case SearchParams.Damage: { if (damageSearchDto.SearchType == SearchType.Greater) { damageList.Sort(SortService.SortDamageAsc); } else if (damageSearchDto.SearchType == SearchType.Lesser) { damageList.Sort(SortService.SortDemageDesc); } else { throw new SearchException(); } break; } } return(Ok(damageList)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <IEnumerable <Dragon> > Get() { return(Ok(_service.GetAll())); }