public async Task <PlaySearchResults> PlaySearchAsync(PlaySearchCriteria searchCriteria, IUser currentUser) { var ds = DataSource(currentUser); var result = new PlaySearchResults() { SearchCriteria = searchCriteria }; var filterParts = new List <string>(); if (searchCriteria.BookKey.HasValue) { filterParts.Add("BookKey = @BookKey"); } if (searchCriteria.FootworkKey.HasValue) { filterParts.Add("EXISTS ( SELECT * FROM Interpretations.PlayStep ps WHERE PlayDetail.PlayKey = ps.PlayKey AND ps.FootworkKey = @FootworkKey)"); result.SearchTerms.Add(await ds.GetByKey("Tags.Footwork", searchCriteria.FootworkKey.Value).ToString("FootworkName").ExecuteAsync()); } if (searchCriteria.TechniqueKey.HasValue) { filterParts.Add("EXISTS ( SELECT * FROM Interpretations.PlayStep ps WHERE PlayDetail.PlayKey = ps.PlayKey AND @TechniqueKey IN (ps.TechniqueKey1, ps.TechniqueKey2, ps.TechniqueKey3))"); result.SearchTerms.Add(await ds.GetByKey("Tags.Technique", searchCriteria.TechniqueKey.Value).ToString("TechniqueName").ExecuteAsync()); } if (searchCriteria.GuardKey.HasValue) { filterParts.Add("(@GuardKey IN (AGuardKey, PGuardKey) OR EXISTS ( SELECT * FROM Interpretations.PlayStep ps WHERE PlayDetail.PlayKey = ps.PlayKey AND @GuardKey in (ps.GuardKey, ps.IntermediateGuardKey)))"); result.SearchTerms.Add(await ds.GetByKey("Tags.Guard", searchCriteria.GuardKey.Value).ToString("GuardName").ExecuteAsync()); } if (searchCriteria.TargetKey.HasValue) { filterParts.Add("EXISTS ( SELECT * FROM Interpretations.PlayStep ps WHERE PlayDetail.PlayKey = ps.PlayKey AND @TargetKey IN (ps.TargetKey1, ps.TargetKey2, ps.TargetKey3))"); result.SearchTerms.Add(await ds.GetByKey("Tags.Target", searchCriteria.TargetKey.Value).ToString("TargetName").ExecuteAsync()); } result.Plays.AddRange(await ds.From("Interpretations.PlayDetail", string.Join(" AND ", filterParts), searchCriteria).ToCollection <PlaySummary>().ExecuteAsync()); if (searchCriteria.BookKey.HasValue) { result.Book = await ds.From("Sources.Book", new { searchCriteria.BookKey }).ToObject <BookSummary>().ExecuteAsync(); } return(result); }
public async Task <IActionResult> Search([FromRoute] int bookKey, [FromQuery] int?guardKey = null, [FromQuery] int?techniqueKey = null, [FromQuery] int?footworkKey = null, [FromQuery] int?targetKey = null) { //bookKey: number, guardKey: number, techniqueKey: number, footworkKey: number, targetKey: number var searchCriteria = new PlaySearchCriteria() { BookKey = bookKey, GuardKey = guardKey, TechniqueKey = techniqueKey, FootworkKey = footworkKey, TargetKey = targetKey }; //if (searchCriteria.IsEmpty) //do we really want to support an empty search page? // return View(new List<PlaySummary>()); //else //{ var model = await m_PlayService.PlaySearchAsync(searchCriteria, await GetCurrentUserAsync()); return(View(model)); //} }