public async Task DistributeMaterialForCompany(string companyName, string sapNr, MaterialDistribution distributionList) { // check that location stock is not exceeded. var current = await GetInventoryItem(sapNr, companyName); foreach (var dist in distributionList.Distribution) { if (dist.Available < 0) { throw new Exception( $"Available is below Zero: Stock {dist.Stock} - Used {dist.Used} - Damage {dist.Damaged} = {dist.Available}"); } } if (current == null) { // initialise inventory current = new MaterialInventoryItem { Company = companyName, SapNr = sapNr }; } //Set new distribution current.Distribution = distributionList.Distribution; await UpsertInventoryItem(companyName, sapNr, current); distributionList.Distribution.ForEach(async dist => { await NewEventJournalEntry(new DistributionChanged(sapNr, companyName, dist.Location, dist)); }); }
public async Task <ActionResult> DistributeMaterialForCompany([FromRoute] string companyName, [FromRoute] string sapNr, MaterialDistribution distributionList) { await _materialInventoryService.DistributeMaterialForCompany(companyName, sapNr, distributionList); return(Ok()); }