public async Task <int> SearchCountAsync(PetFilter filter) { var query = entities.AsQueryable(); query = GetSearchParameters(filter, query); return(await query.CountAsync()); }
public async Task <IEnumerable <Pet> > SearchAsync(PetFilter filter) { var query = entities.AsQueryable(); query = GetSearchParameters(filter, query); query = base.SearchAsync(query, filter); return(await query.AsSplitQuery().ToListAsync()); }
public async Task <IActionResult> Search([FromBody] PetFilter filter) { if (!ModelState.IsValid) { return(BadRequest()); } var pets = await _petRepository.SearchAsync(filter); return(Ok(_mapper.Map <IEnumerable <PetDto> >(pets))); }
public async Task <IActionResult> Search([FromBody] PetFilter filter) { if (!ModelState.IsValid) { return(BadRequest()); } await _notificationHandler.UpsertNotificationAsync(CurrentUser.Id, filter); return(Ok()); }
public async Task <IActionResult> SearchCount([FromBody] PetFilter filter) { if (!ModelState.IsValid) { return(BadRequest()); } var petCount = await _petRepository.SearchCountAsync(filter); return(Ok(new CountResponseDto { Count = petCount })); }
private IQueryable <Pet> GetSearchParameters(PetFilter filter, IQueryable <Pet> query) { if (filter.CreatedSince.HasValue) { query = query.Where(p => p.CreationTimestamp > filter.CreatedSince.Value); } if (filter.AnimalTypes != null && filter.AnimalTypes.Any()) { query = query.Where(p => filter.AnimalTypes.Contains(p.AnimalType.Id)); } if (filter.TraitValues != null && filter.TraitValues.Any()) { foreach (var traitValue in filter.TraitValues) { if (traitValue.Value != null && traitValue.Value.Any()) { query = query.Where(p => p.PetTraits.Any(pt => pt.TraitId == traitValue.Key && pt.TraitOptionId.HasValue && traitValue.Value.Contains(pt.TraitOptionId.Value) ) ); } } } if (filter.BooleanTraits != null && filter.BooleanTraits.Any()) { foreach (var boolTrait in filter.BooleanTraits) { query = query.Where(p => p.PetTraits.Any(pt => pt.TraitId == boolTrait && pt.TraitOption.Option == "כן")); } } if (filter.PetStatus.HasValue) { query = query.Where(p => p.Status == filter.PetStatus.Value); } if (filter.PetSource.HasValue) { query = query.Where(p => p.Source == filter.PetSource.Value); } return(query); }
public async Task UpsertNotificationAsync(int userId, PetFilter filter) { var notifications = await _notificationRepository.SearchAsync(new NotificationFilter { UserId = userId }); var petFilters = notifications.Select(n => JsonConvert.DeserializeObject <PetFilter>(n.PetFilterSerialized)); if (petFilters.Any(pf => pf.GetHashCode() == filter.GetHashCode())) { return; } await _notificationRepository.AddAsync(new Data.Entities.Notification { UserId = userId, PetFilterSerialized = JsonConvert.SerializeObject(filter) }); await _unitOfWork.SaveChangesAsync(); }
public async Task <IList <PetDto> > Search(PetFilter filter) { return(null); }
private void filterClicked(object obj) { ObservableCollection <Item> results = new ObservableCollection <Item>(); // Null check for the combo box if (PetFilter != null) { // Only adds pets if the user did not specify supplies if (SupplyFilter.Contains("All Supplies")) { foreach (Item product in Items) { // Adds animal to the results based on the pet filter combo box and object type if (product.GetType().Equals(typeof(LandAnimal)) && (petFilter.Contains("Land Pet") || PetFilter.Contains("All Pets"))) { results.Add(product); } if (product.GetType().Equals(typeof(AirAnimal)) && (petFilter.Contains("Air Pet") || PetFilter.Contains("All Pets"))) { results.Add(product); } if (product.GetType().Equals(typeof(SeaAnimal)) && (petFilter.Contains("Sea Pet") || PetFilter.Contains("All Pets"))) { results.Add(product); } } } } // Supply filter null check if (SupplyFilter != null) { foreach (Item product in Items) { if (PetFilter.Contains("All Pets")) { if (SupplyFilter.Contains("All Supplies")) { // Adds every item in inventory to the results if (product.GetType().Equals(typeof(Food)) || product.GetType().Equals(typeof(Clothing))) { results.Add(product); } } else if (SupplyFilter.Contains("Food")) { // Adds all of the food in inventory to the results if (product.GetType().Equals(typeof(Food))) { results.Add(product); } } else if (SupplyFilter.Contains("Clothing")) { // Adds all of the clothing in invetory to results if (product.GetType().Equals(typeof(Clothing))) { results.Add(product); } } } else if (PetFilter.Contains("Land Pet")) { // Adds all land pet food based on combo box and animalAttachment variable which establishes relationship between supply and animal if (product.animalAttachment == Item.LandPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies"))) { results.Add(product); } // Adds all land pet clothing based on combo box and animalAttachment variable which establishes relationship between supply and animal else if (product.animalAttachment == Item.LandPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing")) { results.Add(product); } } else if (PetFilter.Contains("Air Pet")) { // See land pet comments for explantion if (product.animalAttachment == Item.AirPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies"))) { results.Add(product); } else if (product.animalAttachment == Item.AirPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing")) { results.Add(product); } } else if (PetFilter.Contains("Sea Pet")) { // See land pet comments for explantion if (product.animalAttachment == Item.SeaPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies"))) { results.Add(product); } else if (product.animalAttachment == Item.SeaPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing")) { results.Add(product); } } } } // Switches to view that diplays results // Passes the main window container, the results list, and the shopping window to return to MainView.ActiveView = new FilterWindowVM(MainView, results, this); }
public ActionResult <IEnumerable <Pet> > Get(PetFilter filter) { return(pets.Where(el => el.Name.IndexOf(filter.Name) != -1).ToList()); }