I have get record by id. It's API run successfully. But i have face issue same record get multiple time
- public SupplementResponse GetSupplementsList(SupplemetParam obj_parameter)
- {
- SupplementResponse obj_result = new SupplementResponse();
- List
lst = new List (); - var PDFURL = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["SupplementUrl"];
- try
- {
- var matchingdata = (from c in _context.TblSupplementDetail
- join sc in _context.SupplementMaster on c.SupplementId equals sc.SupplementId
- where c.UserId == obj_parameter.UserId
- select new
- {
- sc.SupplementId,
- sc.SupplementType,
- sc.SupplementPdf,
- c.SupplementStatus
- }).ToList();
- if (matchingdata.Count > 0)
- {
- foreach (var item in matchingdata)
- {
- SupplementListDetail obj_supplement = new SupplementListDetail();
- obj_supplement.SupplementsId = item.SupplementId;
- obj_supplement.SupplementType = item.SupplementType;
- obj_supplement.SupplementPDF = PDFURL + "" + item.SupplementPdf;
- obj_supplement.SupplementStatus = Convert.ToInt32(item.SupplementStatus);
- lst.Add(obj_supplement);
- }
- }
- var Supplement_List = _context.SupplementMaster.ToList();
- {
- if(Supplement_List .Count >0)
- {
- foreach (var item in Supplement_List)
- {
- if(item.SupplementStatus==false)
- {
- SupplementListDetail obj_supplement = new SupplementListDetail();
- obj_supplement.SupplementsId = item.SupplementId;
- obj_supplement.SupplementType = item.SupplementType;
- obj_supplement.SupplementPDF = PDFURL + "" + item.SupplementPdf;
- obj_supplement.SupplementStatus = Convert.ToInt32(item.SupplementStatus);
- lst.Add(obj_supplement);
- }
- }
- }
- }
- obj_result.Response = 1;
- obj_result.ErrorMessage = "No Error Found";
- List
uniqueLst = lst.Distinct().ToList(); //i have use this here. - obj_result.lst_Supplement = uniqueLst;
- It's me classes.
- public class SupplemetParam
- {
- public int UserId { get; set; }
- }
- public class SupplementResponse
- {
- public int Response { get; set; }
- public string ErrorMessage { get; set; }
- public IEnumerable
lst_Supplement { get; set; } - }
- public class SupplementListDetail
- {
- public int SupplementsId { get; set; }
- public string SupplementType { get; set; }
- public string SupplementPDF { get; set; }
- public int SupplementStatus { get; set; }
- }
Jenith ThakkarRank #789 · 2.9K reputationPosted Aug 10, 2020, 9:54 PM EDT
Posted Aug 10, 2020, 3:17 AM EDT
Dhruval Dave39 reputationPosted Aug 10, 2020, 3:51 AM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted Aug 10, 2020, 8:30 AM EDT
Jenith ThakkarRank #789 · 2.9K reputationPosted Aug 10, 2020, 9:01 PM EDT
Still you're looking for the answer? or have you find it
If you still looking for then you can do it like this way
Create a custom class of distinct
Thank you
Posted Aug 10, 2020, 9:42 PM EDT
Posted Aug 10, 2020, 9:45 PM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted Aug 10, 2020, 10:04 PM EDT
Hamid KhanRank #424 · 5.9K reputationPosted Sep 2, 2020, 9:28 PM EDT
Dhruval Dave39 reputationPosted Aug 10, 2020, 3:12 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts