How to assign values when the if condition matches for LastModifiedDate

Basit Nisar 40 Reputation points
2023-05-05T09:07:00.2466667+00:00
 try
            {
                DateTime _LastModifiedDateTC  ;
                List<CIPHApprovedPutModel> timeSheetApprovedView = new List<CIPHApprovedPutModel>();
                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<int> StateFarmTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList();
                List<int> OtherTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => !x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList();

                int? BaseStateProvinceID = null;
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,853 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
331 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 29,246 Reputation points Microsoft Vendor
    2023-05-08T09:58:08.81+00:00

    Hi @Basit Nisar,

    I think I see what you mean, you can do it with linq statements.

    You can refer to the code below, because I don't know your CIPHApprovedPutModel class, I just wrote the format of the linq statement, you need to change the fields according to your own code.

     List<CIPHApprovedPutModel> timeSheetApprovedView = new List<CIPHApprovedPutModel>();
                var DataList = (from b in timeSheetApprovedView
                                where b.LastModifiedDate == _LastModifiedDateTC
                                select b).ToList();
              
                foreach (var userData in DataList)
                {
                    timeSheetApprovedView.Add(new CIPHApprovedPutModel()
                    {
                        Id = userData.Id,
                        LastModifiedDate = userData.LastModifiedDate,
                       
                    });
                }
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.