Filtering a List using an object field Flutter - flutter

I have a List, PointOfServices, that have an object, Orders.
I want to be able to filter the Points of service, based on the orderType field within the Orders object.
The outcome I want is to have a list of Points of service that only have Orders with an orderType of 'inventory'.
Is this possible and if so, how would i go about implementing this?

Check this:
final filtered = pointOfServices.where((pos) =>
pos.orders.where((order) => order.orderType == 'inventory').isNotEmpty).toList();
You are checking if orders list in a single PointOfService contains one order with order type inventory, if such order is present - this serves as a checker for another filter which takes PointOfService to filtered collection

Related

How do I filter choices from a lookup field that points to a different SharePoint list?

I have an app built based on the a SharePoint list called "Proposal Tracker". One of the fields is a lookup field that provides a drop down from another list called "Employees". I am trying to filter this field, so that when I select it, the only employee names that are shown are the "active" employees.
I've tried adding this into the DataField of the one data card I'm trying to filter, but I get an error.
Filter(Employees,Status.Value = "Active")
Use Filter(CollectionName,Condition)
e.g: Filter(Employees,Status = "Active")
When you have a dropdown control selected you can choose its dependencies from other controls on the screen.
Example:

xamarin forms distinct objects sort based on the no of times that they appear

I have made an Xamarin forms application and the problem that I have a list named lista2 which has an object named poli. Poli is the city that it is located. I want to make a list based on distinct cities, which i have done using this command
var poleislist = lista2.Select(x => x.poli).Distinct();
now I want this poleislist to be sorted based on the amount of times that each element is on the lista2. For example the bigger cities appear more often and I want them in the first places of the list because this list(poleislist) is going to be the itemsource of a picker.
Thank you very much!
Instead of using Distinct you could Group the list, sort it by count descending then Select the poli.
It would be something like this:
var poleislist = lista2.GroupBy(item => item.poli)
.OrderByDescending(a => a.Count())
.Select(x => x.Key)
.ToList();
Note: sorry did not get to test it but this should work. Basically this should get you all the cities in the list, ordered descending by the number of times it appears.
Hope this helps.-

Demandware: Find Product's Category Position?

I'm updating a data feed export, which links a Product to a given Category. I want to also include that product's merchandising position within that category, which currently exists in Business Manger, and is used to control sorting on Product listing pages:
I'm digging through the API docs, and the logical place for this information to be exposed in in dw.catalog.CategoryAssignment, but it's not there. I'm currently inferring the position by essentially doing this:
// assume var product, category
var position = category.products.firstIndex(p => p.ID == product.ID);
However, this tells me where the Product got sorted to, not what the actual Position value is within Demandware. It works for now as an expedient hack, but I really want to replace it with something that pulls the actual value from DW.
Where in the Commerce Cloud API can I find the merchandising position for a given Product in a given Category?
I think you would'nt get the actual position of the product index as you may have multiple sorting rules to display different outputs on the category listing pages. These sorting rules can be created as and when required based on certain rules. I don't think this can be reflected on the product feed.
It took some digging, but I managed to find that the "Position" field for Products in the BM is stored as Product.searchPlacement. To find it, you have to look in Category.products, find the Product you want, and grab the searchPlacement property of that product.
In effect, I used:
// assume var product, category
var position = category.products.find(p => p.ID == product.ID).searchPlacement;
For Products that don't have a Position assigned in the Business Manager, searchPlacement is 0. Otherwise, it reflects the value entered in the BM.

Rest API: How should the filter params send to API in case query based on nested resource

I have two entities Properties and Bookings.
I need to know the URL structure in case I'm filtering the properties base on query on bookings.
In my case I need to get the properties which are free (not occupied) at specific date.
Can it be
api/properties/free/{date}
Or
api/properties/bookings?bookingDate!='1-1-2017'
Or
api/properties?bookingDate!='1-1-2017'
it seems for me that the last one is the more appropriate but the filter is on the bookings not on the properties which is not obvious.
The Facebook Graph API has a interesting way of doing nested queries by using a strategy of fields filter.
The fields filter it´s a way of filter specific fields or nested fields of a rouserce. They also create a standard way to inform functions for every selected field like: limit or equal.
Your request would be something like this:
GET /api/properties?fields=bookings{bookingDate.notEqual('1-1-2017')}
For more information about Facebook´s GraphAPI:
https://developers.facebook.com/docs/graph-api/overview/

Search Logic removing records with no association from results when ordering by that association

I'm using search logic to filter and order my results but it removes records from my results when I order by a association and when that association is not always present for all records.
For example say I have a user model which can have one vehicle model but does not have to, if I have a results table where you can order by the users vehicles make I would hope all users without a vehicle record would be considered empty strings and therefore ordered all at the beginning followed by the other user records which have vehicles ordered by the make name.
Unfortunately all the user records which do not have a vehicle are removed from the results.
Is there anyway round this and still use search logic as I find it extremely useful
I think you'll have to explicitly assign a default vehicle that has an empty name