Hi
How i should pass value to List
C#
public List GetSessionDeliveryParticipantList(DateTime frDate, DateTime toDate, List Student, )
{
List Result = (from t in context.View_SessionDeliveryParticipant_Detailed_Reports
where t.SessionDate.Value.Date >= frDate.Date && t.SessionDate.Value.Date <= toDate.Date
&& (Student.Count != 0 ? Student.Contains(t.StudentID.ToString()) : 1 == 1)
orderby t.SessionDate ascending
select t).ToList();
return Result;
}Thanks

Jignesh KumarRank #91 · 22.9K reputationPosted Apr 7, 2023, 2:31 AM EDT
Hello Ramco,
Please try this one,
public List GetSessionDeliveryParticipantList(DateTime frDate, DateTime toDate, List studentsIds) { List Result = (from t in context.View_SessionDeliveryParticipant_Detailed_Reports where t.SessionDate.Value.Date >= frDate.Date && t.SessionDate.Value.Date <= toDate.Date && studentsIds.Contains(t.StudentID.ToString())) orderby t.SessionDate ascending select t).ToList(); return Result; }while calling this method you need to pass empty list of string
var studentsIds = new List(); // Add all students whose records you want using Add() // studentsIds.Add("1"); // studentsIds.Add("2"); // Call above method using below call var frDate = FromDate; var toDate = ToDate ; var result = GetSessionDeliveryParticipantList(frDate,toDate,studentsIds);Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 7, 2023, 2:22 AM EDT
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 9, 2023, 4:49 PM EDT
public List GetSessionDeliveryParticipantList(DateTime frDate, DateTime toDate, List studentsIds) { if (frDate == null || toDate == null || studentsIds == null || !studentsIds.Any()) { throw new ArgumentException("Invalid input parameters."); } List result = (from t in context.View_SessionDeliveryParticipant_Detailed_Reports where t.SessionDate.Value.Date >= frDate.Date && t.SessionDate.Value.Date <= toDate.Date && studentsIds.Contains(t.StudentID.ToString()) orderby t.SessionDate ascending select t).ToList(); return result; }In this modified version of the code, I've added parameter validation in the form of an ArgumentException if any of the input parameters are null or empty. I've also changed the variable name Result to result to follow C# naming conventions, and added consistent indentation and spacing.