public async Task DistributeGradeForCompany(string companyName, Grade grade, GradeDistribution distributionList)
        {
            // check that location stock is not exceeded.
            var current = await GetInventoryItem(grade, 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.Detached} = {dist.Available}");
                }
            }

            if (current == null)
            {
                // initialise inventory
                current = new ServantInventoryItem {
                    Company = companyName, Grade = grade
                };
            }

            //Set new distribution
            current.Distribution = distributionList.Distribution;

            await UpsertInventoryItem(companyName, grade, current);

            distributionList.Distribution.ForEach(async dist => { await NewEventJournalEntry(new DistributionChanged(grade, companyName, dist.Location, dist)); });
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> DistributeServantsForCompany([FromRoute] string companyName, [FromRoute] Grade grade, GradeDistribution distributionList)
        {
            await _inventoryService.DistributeGradeForCompany(companyName, grade, distributionList);

            return(Ok());
        }