Basit Nisar

Basit Nisar

  • 1.7k
  • 84
  • 11k

my code must run if block not else

Apr 3 2023 9:01 AM
bool IsDateNotMatched = false;
bool IsDataNotFound = false;
try
{

    var contatDetail = db.Contacts.AsNoTracking().Where(x => x.ContactID == LogedInID).Select(x => new
    {
        x.FirstName,
        x.MiddleName,
        x.LastName,
        x.EmployeeNumber
    }).FirstOrDefault();

    int? BaseStateProvinceID = null;
    //List<int> TimeCardIDs = cipdApprovedView.ContractInvoicePerDays.Split(',').Select(int.Parse).ToList();
    List<ContractInvoicePerDay2> ContractInvoicePerDays = new List<ContractInvoicePerDay2>();
    ContractInvoicePerDays = cipdApprovedView.contractInvoicePerDay2s.ToList();
    //if (TimeCardIDs.Count == 1)
    //{
    //    BaseStateProvinceID = cipdApprovedView.BaseStateProvinceID;
    //}

    foreach (var item in ContractInvoicePerDays)
    {
        ContractInvoicePerDay contractInvoicePerDay = db.ContractInvoicePerDays.Find(item.ContractInvoicePerDayID);
        DateTime _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(item.ContractInvoicePerDayID, (int)InvoiceSourceTypes.PerDay).GetValueOrDefault();
        if ( item.LastModifiedDate == _LastModifiedDateTC && IsDateNotMatched )
        {

            if ( IsDataNotFound  && contractInvoicePerDay != null )
            {
                contractInvoicePerDay.StatusID = 4; //Approved
                contractInvoicePerDay.ApprovedBy = (string.IsNullOrEmpty(contatDetail.FirstName) == false ? contatDetail.FirstName + " " : "") + (string.IsNullOrEmpty(contatDetail.LastName) == false ? contatDetail.LastName : "");
                contractInvoicePerDay.ApprovedDate = DateTime.Now;
                contractInvoicePerDay.ApprovedByManagerID = LogedInID;
                contractInvoicePerDay.LastUpdatedBy = LogedInID;
                contractInvoicePerDay.LastUpdatedIsCATStaff = false;

                if (BaseStateProvinceID != null && BaseStateProvinceID > 0)
                {
                    contractInvoicePerDay.BaseStateProvinceID = BaseStateProvinceID;
                }

                db.Entry(contractInvoicePerDay).State = EntityState.Modified;

                await db.SaveChangesAsync();

                //Notification code is working fine, Commented because discussed with DJ and Bhawesh



            }
            else
            {
                IsDataNotFound = true;
               
            }

        }
        else
        {
            IsDateNotMatched = true;
            

        }

 


Answers (1)