/// <summary> /// Updates a material batch. /// </summary> /// <param name="batchId">The ID of the batch to update.</param> /// <param name="material">The material this batch consists of.</param> /// <param name="expirationDate">The expiration date of the material.</param> /// <param name="storageLocation">The storage location of the batch.</param> /// <param name="batchNumber">The batch number.</param> /// <param name="customProps">The custom prop values for this batch.</param> /// <exception cref="MaterialBatchNotFoundException">Thrown if no matching batch could be found.</exception> /// <returns>Returns the updated batch.</returns> public MaterialBatch UpdateMaterialBatch(Guid batchId, Material material, DateTime expirationDate, StorageLocation storageLocation, long batchNumber, Dictionary <Guid, string> customProps) { // Get batch MaterialBatch batch = GetBatchOrThrowNotFoundException(batchId); // Validate expirationd date IEnumerable <Transaction> log = TransactionLogService.GetTransactionLog(batchId); DateTime originalCheckIn = log.Last().Timestamp.Date; if (expirationDate <= originalCheckIn) { throw new ArgumentException("The expiration date cannot be set prior to the original check in date of the material batch."); } // Proceed with update batch.Material = material; batch.ExpirationDate = expirationDate; batch.StorageLocation = storageLocation; batch.BatchNumber = batchNumber; batch.CustomProps = customProps; MaterialBatchRepository.UpdateMaterialBatch(batch); return(batch); }
/// <summary> /// Retrieves all related material data from a transaction. /// </summary> /// <typeparam name="Guid">ID of the transaction to use as a starting point.</typeparam> /// <returns>Returns a trace result on success.</returns> /// <exception cref="Exceptions.TransactionNotFoundException" /> /// <exception cref="Exceptions.MaterialBatchNotFoundException" /> /// <exception cref="Exceptions.MaterialNotFoundException" /> public TraceResult Trace(Guid transactionId) { // Get checkout transaction Transaction checkOutTransaction = TransactionLogService.GetTransaction(transactionId); // Get checkin transaction Transaction checkInTransaction = TransactionLogService.GetTransactionLog(checkOutTransaction.MaterialBatchId).Last(); // Get batch MaterialBatch batch = InventoryService.GetMaterialBatch(checkOutTransaction.MaterialBatchId); // Get and replace material data in extra step, since the InventoryService currently doesn't return custom material prop values Material material = MaterialsService.GetMaterial(batch.Material.Id); batch.Material = material; // Get temperature extrema Extrema temperature = EnvironmentService.GetExtrema(batch.StorageLocation.StorageSiteId, EnvironmentalFactor.Temperature, checkInTransaction.Timestamp, checkOutTransaction.Timestamp); // Get humidity extrema Extrema humidity = EnvironmentService.GetExtrema(batch.StorageLocation.StorageSiteId, EnvironmentalFactor.Humidity, checkInTransaction.Timestamp, checkOutTransaction.Timestamp); // Return trace result object return(new TraceResult() { Batch = batch, CheckInTransaction = checkInTransaction, CheckOutTransaction = checkOutTransaction, Temperature = temperature, Humidity = humidity }); }
/// <summary> /// Gets the full transaction log of a material batch. /// </summary> /// <param name="batchId">The ID of the batch to get the log for..</param> /// <exception cref="MaterialBatchNotFoundException">Thrown if no matching batch could be found.</exception> /// <returns>Returns all matching transactions.</returns> public IEnumerable <Transaction> GetMaterialBatchTransactionLog(Guid batchId) { GetBatchOrThrowNotFoundException(batchId); return(TransactionLogService.GetTransactionLog(batchId)); }