2017-06-21 70 views
0

我需要周圍oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service)?.Expire(service);創建一個布爾值,並將其設置爲true,如果oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service) is not null如何創建布爾?

任何意見,如何做到這一點的布爾?下面是我的代碼?

public static void HandleLinkersForUpgrade(List<CatalogItemToOrganisationLinker> latestLinkers, List<CatalogItemToOrganisationLinker> oldLinkers, Account account, Invoice invoice, IOrganizationService service) 
    { 
     var newSupplierLinker = latestLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Supplier, service); 
     var oldSupplierLinker = oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Supplier, service); 

     var newSupplierLevel = newSupplierLinker?.ToTargetLevel(service); 
     var oldSupplierLevel = oldSupplierLinker?.ToTargetLevel(service); 

     if (newSupplierLevel > oldSupplierLevel) 
     { 
      //create the bool around line below 
      oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service)?.Expire(service); 
      oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.DTS, service)?.Expire(service); 
      oldSupplierLinker.Expire(service); 

     } 

     var oldBuyerLinker = oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Buyer, service); 
     var newBuyerLinker = latestLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Buyer, service); 

     if (oldBuyerLinker != null && newBuyerLinker != null) 
     { 
      oldBuyerLinker.Expire(service); 
     } 

     foreach (var catItemLinker in latestLinkers) 
     { 
      if (catItemLinker.Category(service) == mm_catalogitemcategory.Acclaim) 
      { 
       UpgradeLogic.AcclaimUpgradeLogic(account, service); 
      } 

      if (oldSupplierLevel == 3) 
      { 
       var l3Linker = service.GetSetSectionToOrgLinker(account.Id, "L3"); 

       if (l3Linker?.SectionStatus == mm_status.Verified && catItemLinker.ToTargetLevel(service) == 4) // Hack to get OAR workflows to run 
       { 
        l3Linker.SectionStatus = mm_status.AwaitingVerification; 
        l3Linker.Update(service); 
        l3Linker.SectionStatus = mm_status.Verified; 
        l3Linker.Update(service); 
       } 
      } 

      catItemLinker.MakeLive(invoice, service); 
     } 

     if (newSupplierLinker != null) 
     { 
      newSupplierLinker.TopAchievedCertificate = oldSupplierLinker?.TopAchievedCertificate; 
      newSupplierLinker.Update(service); 
     } 
    } 
+1

好嗎?所以做一個布爾值,如果它不爲null,則將其設置爲false。也許我誤解了你的問題,但這非常簡單。如果你無法弄清楚,那麼選擇一個基本的教程,因爲如果是這樣的話,你錯過了一些非常基礎的東西。 – tnw

+1

不確定你的意思是「創建一個布爾」。你問如何創建布爾變量?像'var isOldLinkersNull = false;'? – bnem

+0

@bnem我的朋友說,如果oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim,service)不爲null,則將其設置爲true,然後將其傳遞給讚譽升級邏輯 ,然後只調用複製表單的部分(如果bool爲假) –

回答

0
bool result = oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service)?.Expire(service) ?? oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service) != null ? true: false; 

我認爲這會工作

+0

沒有工作,是否有另一種簡單的方法來做到這一點? –

+1

@WaqarMalik *如何做不到的?三元一樣簡單。 – tnw

+0

@WaqarMalik你能解釋一下更多什麼問題與我的建議,也可能是一個工作的例子或更好的解釋,你期待什麼請:) – user2120315