BatchSupplyChainQueryData ISupplyChainService.GetSimpleBatchSupplyChain(Guid batchId) { var result = new BatchSupplyChainQueryData(); var tempTenants = new List <Tenant>(); var transfersOfThatBatch = medicineBatchTransferRepository.GetAll() .Where(t => t.MedicineBatchId == batchId) .ToList(); transfersOfThatBatch = transfersOfThatBatch.OrderBy(t => t.Tier).ToList(); foreach (var transfer in transfersOfThatBatch) { result.Transfers.Add(transfer.ToMedicineBatchTransferQueryData()); tempTenants.Add(transfer.From); tempTenants.Add(transfer.To); } result.TotalTransfers = (uint)result.Transfers.Count(); result.TotalTenants = (uint)tempTenants.GroupBy(t => t.Id).Count(); return(result); }
public IActionResult GetSupplyChain(Guid batchId, [FromQuery] bool?isDetailed) { try { if (isDetailed.HasValue && isDetailed.Value == true) { DetailedBatchSupplyChainQueryData result = supplyChainService.GetDetailedBatchSupplyChain(batchId); return(Ok(result)); } else { BatchSupplyChainQueryData result = supplyChainService.GetSimpleBatchSupplyChain(batchId); return(Ok(result)); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }