C#
try
{
DateTime _LastModifiedDateTC ;
List timeSheetApprovedView = new List();
foreach (var Item in timeSheetApprovedView.TimeCards)
{
if (Item.IsStateFarm == true)
{
_LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.TimeCard).GetValueOrDefault();
}
else
{
_LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.PerHour).GetValueOrDefault();
}
if (Item.LastModifiedDate == _LastModifiedDateTC)
{
//how to assign values when condition matches
}
}
List StateFarmTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList();
List OtherTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => !x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList();
int? BaseStateProvinceID = null;
Tuhin PaulRank #7 · 71.9K reputationPosted May 5, 2023, 4:56 AM EDT
To assign values when the condition matches, see the code here :
foreach (var Item in timeSheetApprovedView.TimeCards) { if (Item.IsStateFarm == true) { _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.TimeCard).GetValueOrDefault(); } else { _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.PerHour).GetValueOrDefault(); } if (Item.LastModifiedDate == _LastModifiedDateTC) { // If the condition matches, you can assign values to the variables here StateFarmTimeCardIDs.Add(Item.TimeCardID); BaseStateProvinceID = Item.BaseStateProvinceID; } }In the code above, we first check if the condition Item.LastModifiedDate == _LastModifiedDateTC matches for the current item. If it does, we can then assign the values to the variables StateFarmTimeCardIDs and BaseStateProvinceID as needed.
The code above assumes that StateFarmTimeCardIDs and BaseStateProvinceID have already been declared and initialized earlier in the code. If not, you'll need to add the appropriate declarations before the foreach loop.
Basit Nisar97 reputationPosted May 5, 2023, 6:42 AM EDT
not just StateFarmTimeCardIDs here we have OtherTimeCardIDs so anyway to add in this list timeSheetApprovedView??