Reputation: 1900
I have a collection list which contains the following fields
I want to seach within this list against another date list. For every date in the second list I want to get records starting between this minimum date and the next date is which (30 minutes to the minium date).
foreach (var item in selectedDates.Where(x => x.Checked))
{
// item.minDate is my starting date
// I want all records between item.minDate and 30 minutes added to it)
var t = lf.ReplicateBlocks.FindAll(o=> o.minimumCompletionDate >= item.
}
**UPDATE**
public class ReplicateBlock
{
public int ReplicateId { get; set; }
public string AssayNumber { get; set; }
public DateTime InitiationDate { get; set; }
public DateTime InitiationTime { get; set; }
public DateTime minimumCompletionDate { get; set; }
public DateTime minimumCompletionTime { get; set; }
public string correctedCount { get; set; }
public string moduleName { get; set; }
public string exception { get; set; }
}
public class RunLogEntryDatesDisplay
{
public DateTime runDate { get; set; }
public String DateRange { get; set; }
public bool Checked { get; set; }
public string MinimumReplicateId { get; set; }
}
The final output I am looking for is a revised Replicate Block list. RunLogEntryDatesDisplay is a checkbox list posted from the view. In this list I look at the checked date which is runDate and starting from the first selection I add 30 minutes to it and find all records in ReplicateBlock List in between and the edges. I will do the same for every selected date in the checbox list and in the end will have a final/filtered ReplicateBlockLisr based on users selections(checked item).
Upvotes: 0
Views: 356
Reputation: 152644
You could loop through the dates and populate a result list:
List<ReplicateBlock> blocks = new List<ReplicateBlock>();
foreach (var item in selectedDates.Where(x => x.Checked))
{
var t = lf.ReplicateBlocks.Where(o=>
o.minimumCompletionDate >= item.minDate &&
o.minimumCompletionDate <= item.minDate.AddMinutes(30));
blocks.AddRange(t);
}
You could also do it in one query:
var query = from d in selectedDates
from o in lf.ReplicateBlocks
where d.Checked &&
o.minimumCompletionDate >= d.minDate &&
o.minimumCompletionDate <= d.minDate.AddMinutes(30))
select o;
Upvotes: 2