Merging data from two lists conditionally
table structure is as following
MobileID ModelID ManufacturerID IsApproved
where IsApproved is boolean value,
When new mobile entry done in database, it goes for the approval to the manager, till that it’s IsApproved value is 0, when it gets approved IsApproved value will become 1.
I want to do as following
I am getting the list of all approved mobile using first query written below
now problem is I have to display all the mobiles based on 2 conditions
1) If a mobile exists with same modelID and manufacturerID (means the specification is updated) than it’s IsApproved field will become 0 –> not in DB but into the list for display purpose only)
2) If Mobile is new than it’s IsApproved status should be 0
What should I do to merge this two lists conditionally?
My LINQ queries are as below
var listApproved = objMobile.MobileLists.where(mb => mb.IsApproved == true).toList();
var listUnApproved = objMobile.MobileLists.where(mb => mb.IsApproved == false).toList();
Suppose table data is as following
MobileID ModelID ManufacturerID IsApproved
01 mod1 manu1 1
02 mod2 manu2 1
03 mod3 manu3 1
04 mod1 manu1 0
05 mod5 manu5 0
06 mod6 manu6 0
07 mod2 manu2 0
I Want the list as
MobileID ModelID ManufacturerID IsApproved
01 mod1 manu1 0
02 mod2 manu2 0
03 mod3 manu3 1
05 mod5 manu5 0
05 mod6 manu6 0
Well, first let’s cache your list in memory to save us getting it more than once:
Now let’s do your logic to get all the mobiles:
EDIT: The above code will set the correct values, but it won’t filter out the mobiles with the duplicate
ManufacturerIdandModelID. You’ll have to use an additionalforeachfor that, like so: