/// <summary> /// Internal Method for Evaluate /// </summary> protected override void EvaluateInternal() { // Initialized all rules. Instancing only takes place during execution, since otherwise the service scope has not yet been assigned Context.Rules = new RulesBundle(Context, this); var loadCarrierRepository = ServiceProvider.GetService <IRepository <Olma.LoadCarrier> >(); Olma.LoadCarrier loadCarrier = loadCarrierRepository .FindByCondition(lc => lc.Id == Context.Request.LoadCarrierId) .Include(lct => lct.Type).ThenInclude(blc => blc.BaseLoadCarrierMappings).FirstOrDefault(); if (loadCarrier == null) { return; } switch (loadCarrier.Type.BaseLoadCarrier) { case BaseLoadCarrierInfo.None when Context.Request.BaseLoadCarrierId != null: RuleState.Add(ResourceName, new RuleState { RuleStateItems = { Message } }); break; case BaseLoadCarrierInfo.Required when Context.Request.BaseLoadCarrierId == null: RuleState.Add(ResourceName, new RuleState { RuleStateItems = { new BaseLoadCarrierRequired() } }); break; default: { if (loadCarrier.Type.BaseLoadCarrier != BaseLoadCarrierInfo.None && Context.Request.BaseLoadCarrierId != null && loadCarrier.Type.BaseLoadCarrierMappings.All(blc => blc.LoadCarrierId != Context.Request.BaseLoadCarrierId)) { RuleState.Add(ResourceName, new RuleState { RuleStateItems = { new BaseLoadCarrierError() } }); } break; } } }
private Contracts.Models.ExpressCode GetExpressCodeByDigitalCode() { var avail2deli = LmsAvail2deliRepository.FindAll() .Where(ad => ad.ExpressCode == DigitalCode && ad.State == 2 && ad.FrachtpapiereErstellt.Value && ad.DeletionDate == null ) .Include(ad => ad.Availability) .Include(ad => ad.Delivery).AsNoTracking().FirstOrDefault(); if (avail2deli == null) { return(null); } var loadCarriers = LoadCarrierRepository.FindAll() .Include(lc => lc.Quality).ThenInclude(q => q.Mappings) .Include(lc => lc.Type) .FromCache().ToList(); var loadCarrier = loadCarriers .SingleOrDefault(lc => lc.Type.RefLmsLoadCarrierTypeId == avail2deli.PalletTypeId && lc.Quality.Mappings.SingleOrDefault(qm => qm.RefLmsQualityId == avail2deli.QualityId) != null); Olma.LoadCarrier baseLoadCarrier = null; if (avail2deli.BaseQuantity != null && avail2deli.BaseQuantity != 0) { baseLoadCarrier = loadCarriers .SingleOrDefault(lc => lc.Type.RefLmsLoadCarrierTypeId == avail2deli.BasePalletTypeId && lc.Quality.Mappings.SingleOrDefault(qm => qm.RefLmsQualityId == avail2deli.BaseQualityId) != null); } if (loadCarrier == null) { return(null); } int?ltmsAccountId; switch (PrintType) { case B2b.Common.Enumerations.PrintType.LoadCarrierReceiptDelivery: ltmsAccountId = avail2deli.Delivery.LtmsAccountId; break; case B2b.Common.Enumerations.PrintType.LoadCarrierReceiptPickup: ltmsAccountId = avail2deli.Availability.LtmsAccountId; break; default: return(null); } var postingAccount = PostingAccountRepository.FindAll() .Where(pa => pa.RefLtmsAccountId == ltmsAccountId) .AsNoTracking().FirstOrDefault(); if (postingAccount == null) { return(null); } var expressCode = new Contracts.Models.ExpressCode { DigitalCode = DigitalCode, LoadCarrierReceiptPreset = new LoadCarrierReceiptPreset { DeliveryNoteNumber = avail2deli.Delivery?.DeliveryNoteNo, PickupNoteNumber = avail2deli.Availability?.ContractNo, RefLmsBusinessTypeId = avail2deli.Delivery?.BusinessTypeId, LoadCarrierId = loadCarrier.Id, LoadCarrierQuantity = avail2deli.Quantity, BaseLoadCarrierId = baseLoadCarrier?.Id, BaseLoadCarrierQuantity = avail2deli.BaseQuantity, PostingAccountId = postingAccount.Id, Type = PrintType == B2b.Common.Enumerations.PrintType.LoadCarrierReceiptPickup ? LoadCarrierReceiptType.Pickup : LoadCarrierReceiptType.Delivery, PlannedFulfillmentDateTime = avail2deli.LadeterminDatum, RefLtmsTransactionRowGuid = avail2deli.RefLtmsTransactionRowGuid } }; return(expressCode); }