Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public ActionResult GetDocument(int? DocumentTypeId)
        {
            int id = (int)Session["ApplicationId"];
            var DropDataChild = new List<documentslists>();
            var ChkDocumentData = new List<documentslists>();
            var AppDocData = new List<documentslists>();
            int chk = 0;

            ChkDocumentData = (from a in dbContext.SysDocuments
                               join b in dbContext.SysDocumentTypes
                               on a.DocumentTypeId equals DocumentTypeId
                               select new DocumentsLists
                               {
                                   DocumentId = a.DocumentId,
                                   DocumentName = a.DocumentName
                               }).Distinct().ToList();
            foreach (var z in ChkDocumentData)
            {
                AppDocData = (from c in dbContext.KenPartnerAppDocuments
                              join d in dbContext.SysDocuments on c.DocumentId equals d.DocumentId
                              where c.ApplicationId == id && c.DocumentId == z.DocumentId
                              select new DocumentsLists
                              {
                                  DocumentId = d.DocumentId,
                                  DocumentName = d.DocumentName
                              }).ToList();
                if (AppDocData.Count > 0)
                {
                    chk++;
                   
                }
            }
            if (chk > 0)
            {
               DropDataChild = ChkDocumentData.Except(AppDocData).ToList();
               
            }

          

            
            return Json(DropDataChild, JsonRequestBehavior.AllowGet);
        }
Posted
Updated 29-Oct-15 20:42pm
v4
Comments
Krunal Rohit 30-Oct-15 1:49am    
What ?

-KR
ARYA JAGANNATH 30-Oct-15 2:35am    
Class-->

public class DocumentsLists
{
public int DocumentId { get; set; }
public string DocumentName { get; set; }
}

List-->
var ChkDocumentData = new List<documentslists>();
var AppDocData = new List<documentslists>();

Contents of two list-->

ChkDocumentData contains {{DocumentId = 42, DocumentName ="Passport"},{DocumentId = 44, DocumentName ="Adhar Card"},
{DocumentId = 45, DocumentName ="Driving License"},{DocumentId = 46, DocumentName ="Voter ICard"}};

AppDocData contains {DocumentId = 44, DocumentName ="Adhar Card"};


I want a list Contains {{DocumentId = 42, DocumentName ="Passport"},{DocumentId = 45, DocumentName ="Driving License"},{DocumentId = 46, DocumentName ="Voter ICard"}};

Thanks in advance
Maciej Los 30-Oct-15 3:23am    
Do NOT repost[^]!!!

Try with below code:
C#
var ChkDocumentData = new List<documentslists>()
{
	new DocumentsLists {DocumentId = 42, DocumentName ="Passport"},
	new DocumentsLists {DocumentId = 44, DocumentName ="Adhar Card"},
	new DocumentsLists {DocumentId = 45, DocumentName ="Driving License"},
	new DocumentsLists {DocumentId = 46, DocumentName ="Voter ICard"}
};

var AppDocData = new List<documentslists>()
 {
	new DocumentsLists {DocumentId = 44, DocumentName ="Adhar Card"}
};

List<documentslists> tempList = ChkDocumentData.Concat(AppDocData).ToList<documentslists>();

var idList = tempList.Select(x => new { x.DocumentId, x.DocumentName }).Distinct();
foreach(var temp in idList)
{
   int DocumentId =  temp.DocumentId; 
   string DocumentId = temp.DocumentName;
}

You can do it different ways(distinctby), here is one solution.
 
Share this answer
 
v2
Another way of getting distinct items from two lists is as below

C#
List<testclass> L1 = new List<testclass>();
           List<testclass> L2 = new List<testclass>();
           L1.Add(new testClass() { ID = 4, Name = "dfghdfhdfh" });
           L1.Add(new testClass() { ID = 5, Name = "d6fghdfhdfh" });
           L1.Add(new testClass() { ID = 6, Name = "5dfghdfhdfh" });
           L2.Add(new testClass() { ID = 4, Name = "dfghdfhdfh" });
           L1.Add(new testClass() { ID = 41, Name = "dfghdfhdfh" });
           L2.Add(new testClass() { ID = 15, Name = "1d6fghdfhdfh" });

           var x1 =
                (from msg in L1
                where !L2.Any(x => x.ID == msg.ID && x.Name == msg.Name)
                select msg)
                .Concat(from msg in L2
                        where !L1.Any(x => x.ID == msg.ID && x.Name == msg.Name)
                        select msg)
                ;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900