.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
the problem is that i have to make a group by with the partnerid when i try to avoid the partner of the user, cause others users can have been added for the partner and so i will see it on my list anyway..
i explain better:
Users : Carlos, Kamil, Franco
Carlos added for partner A, B, C, E
Kamila added for partner B, C,
Francoadded for partner C, D, E
So if i want to show the partners non already given to Carlos, with this code i will still show B C E, cause are added for the 2 other users and this code check the PArnterUSers Table.. so how to modify my code?
Member
327 Points
1770 Posts
Show in my dropdown list only the Partners with the goog user
Dec 17, 2020 10:12 AM|grafic.web|LINK
Hi,
i generate a SelectList
id = USER I CHOOSE var PartnerData = db.Partner .Where(m => m.ListPartnerUser. ( UserId taken from my PartnerUsers table) != id) .Select(m => new { PartnerId = m.PartnerId, PartnerTitleAndLangue = m.PartnerTitle + " (" + m.PartnerLangue + ")" }) .ToList(); ViewBag.PartnerId = new SelectList(PartnerData, "PartnerId", "PartnerTitleAndLangue");
which i use to populate my dropdownlist
I have thos two models
and i need to show only the partners that HAVE NOT already the user saved for that partner in the PartnerUsers
How to modify my code?
Contributor
2380 Points
683 Posts
Re: Show in my dropdown list only the Partners with the goog user
Dec 18, 2020 09:46 AM|YihuiSun|LINK
Hi grafic.web,
Do you want to get all the partners that the user(for example, UserId="1")does not have?
If this is the case, you can refer to the following code.
If this is not the case, can you describe your problem in more detail?
Model
Controller
[HttpPost] public ActionResult Index(string UserId) { var allpartners = db.Partners.ToList(); var partnerUsersWithUserId = db.PartnerUsers.Include("ListPartnerForUser") .Where(m => m.UserId == UserId) .Select(m => m.ListPartnerForUser.ToList()).FirstOrDefault(); var exceptPartner = partnerUsersWithUserId != null ?allpartners.Except(partnerUsersWithUserId).ToList():null; if(exceptPartner != null) { var PartnerData = exceptPartner.Select(m => new { PartnerId = m.PartnerId, PartnerTitleAndLangue = m.PartnerTitle + " (" + m.PartnerLangue + ")" }); ViewBag.PartnerId = new SelectList(PartnerData, "PartnerId", "PartnerTitleAndLangue"); ViewBag.Message = UserId; } else { ViewBag.PartnerId = null; ViewBag.Message = "NO Partner"; } return View(); }
View
Here is the result.
Best Regards,
YihuiSun
Member
327 Points
1770 Posts
Re: Show in my dropdown list only the Partners with the goog user
Dec 18, 2020 11:02 AM|grafic.web|LINK
Hi,
i am lost...
i do not get your code..
why you take off the partnerid from my table PartnerUsers?
In this table i add one or more user for each partner i want..
So let say i wanto to add Carlos to the partner 1 and 2
I add in my PartnerUsers table
Userid: Carlos , Partnerid : 1
Userid: Carlos , Partnerid : 2
So i need to show in the list of partners only the parners 3 and 4 because carlos is not added in the PartnerUsers table for the partners 3 and 4.
I hope i explained better what i need to achive
Member
327 Points
1770 Posts
Re: Show in my dropdown list only the Partners with the goog user
Dec 18, 2020 12:55 PM|grafic.web|LINK
Hi,
i am almost there... i modify with this code :
model :
controller
the problem is that i have to make a group by with the partnerid when i try to avoid the partner of the user, cause others users can have been added for the partner and so i will see it on my list anyway..
i explain better:
Users : Carlos, Kamil, Franco
Carlos added for partner A, B, C, E
Kamila added for partner B, C,
Francoadded for partner C, D, E
So if i want to show the partners non already given to Carlos, with this code i will still show B C E, cause are added for the 2 other users and this code check the PArnterUSers Table.. so how to modify my code?
I hope i explained well
Member
327 Points
1770 Posts
Re: Show in my dropdown list only the Partners with the goog user
Dec 18, 2020 02:04 PM|grafic.web|LINK
Here the solution!
i finally Find it ;)