public Remaining ( System.Guid notificationId ) : Task |
||
notificationId | System.Guid | |
return | Task |
public async Task <MovementDetails> Create(Movement movement, ShipmentQuantity shipmentQuantity, IEnumerable <PackagingInfo> packages) { var remaining = await movementsQuantity.Remaining(movement.NotificationId); if (shipmentQuantity > remaining) { throw new InvalidOperationException(string.Format( "Cannot create new movement details for movement {0} as the quantity exceeds what is remaining", movement.Id)); } return(new MovementDetails(movement.Id, shipmentQuantity, packages)); }
public async Task <Movement> Create(Guid notificationId, DateTime actualMovementDate) { await dateValidator.EnsureDateValid(notificationId, actualMovementDate); var hasMaximumMovements = await numberOfMovements.HasMaximum(notificationId); if (hasMaximumMovements) { throw new InvalidOperationException( string.Format("Cannot create new movement for notification {0} which has used all available movements", notificationId)); } var hasMaximumActiveLoads = await numberOfActiveLoads.HasMaximum(notificationId, actualMovementDate); if (hasMaximumActiveLoads) { throw new InvalidOperationException( string.Format("Cannot create new movement for notification {0} because permitted active loads would be exceeded", notificationId)); } var quantityRemaining = await movementsQuantity.Remaining(notificationId); if (quantityRemaining <= new ShipmentQuantity(0, quantityRemaining.Units)) { throw new InvalidOperationException( string.Format("Cannot create new movement for notification {0} as the quantity has been reached or exceeded.", notificationId)); } var notificationStatus = (await assessmentRepository.GetByNotificationId(notificationId)).Status; if (notificationStatus != NotificationStatus.Consented) { throw new InvalidOperationException( string.Format("Cannot create a movement for notification {0} because its status is {1}", notificationId, notificationStatus)); } var financialGuaranteeCollection = await financialGuaranteeRepository.GetByNotificationId(notificationId); if (!financialGuaranteeCollection.FinancialGuarantees.Any(fg => fg.Status == FinancialGuaranteeStatus.Approved)) { throw new InvalidOperationException( string.Format("Cannot create a movement for notification {0} because there are no approved financial guarantees", notificationId)); } var consentPeriodExpired = await consentPeriod.HasExpired(notificationId); if (consentPeriodExpired) { throw new InvalidOperationException( string.Format("Cannot create new movement for notification {0} because the consent period has passed", notificationId)); } var newNumber = await numberGenerator.Generate(notificationId); return(new Movement(newNumber, notificationId, actualMovementDate, userContext.UserId)); }