public async Task <ActionResult <IEnumerable <PlaceProduct> > > ListPlaceProductByCategory( [FromQuery] string category ) { try { return(Ok(await placeProviderRepository.ListPlaceProductByCategory(category))); } catch (ArgumentException exc) { logger.LogError(exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } catch (Exception exc) { logger.LogError(exc, exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } }
public async Task <ActionResult <Dictionary <string, Place> > > ListFiltered([FromQuery] string category = "all", [FromQuery] string availability = "all") { try { if (string.IsNullOrEmpty(category)) { category = "all"; } if (string.IsNullOrEmpty(availability)) { availability = "all"; } var places = await placeRepository.ListAll(); if (category != "all") { var onlyInsured = false; if (category.EndsWith("-doctor")) { onlyInsured = true; category = category.Replace("-doctor", ""); } if (category.EndsWith("-self")) { onlyInsured = false; category = category.Replace("-self", ""); } var pprs = await placeProviderRepository.ListPlaceProductByCategory(category); if (onlyInsured) { pprs = pprs.Where(ppr => ppr.InsuranceOnly == true); } var ids = pprs.Select(ppr => ppr.PlaceId).Distinct().Where(id => !string.IsNullOrEmpty(id)).ToHashSet(); places = places.Where(place => ids.Contains(place.Id)); } if (availability == "all") { return(Ok(places.ToDictionary(p => p.Id, p => p))); } var ret = new List <Place>(); ///@TODO return(Ok(ret.ToDictionary(p => p.Id, p => p))); } catch (Exception exc) { logger.LogError(exc, exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } }