如何创建布尔值?

时间:2017-06-21 15:36:32

标签: c# crm boolean-expression

我需要在oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service)?.Expire(service);周围创建一个bool,并在oldLinkers.GetNewestLinkerByCategory(mm_catalogitemcategory.Acclaim, service) is not null

时将其设置为true

任何建议如何做到这个布尔值?下面是我的代码?

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 个答案:

答案 0 :(得分:0)

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

我认为那会工作