コード例 #1
0
        public async Task <ActionResult> CorrectServantStock(string company, Grade grade, string location,
                                                             PatchAmount newStock)
        {
            var current = await _inventoryService.GetInventoryItem(grade, company);

            if (current == null)
            {
                return(BadRequest("No inventory available"));
            }


            if (newStock.Amount < 0)
            {
                return(BadRequest("Stock must be a positive value"));
            }

            // TODO check if we need to validate if new stock is exceeded (newStock - used - damaged)?
            current.Distribution.First(item => item.Location == location).Stock = newStock.Amount;

            await _inventoryService.UpsertInventoryItem(company, grade, current);

            await _inventoryService.NewEventJournalEntry(new StockCorrected(grade, company, location, newStock.Amount));

            return(Ok());
        }
コード例 #2
0
        public async Task <ActionResult> ServantUsed([FromRoute] string company, [FromRoute] Grade grade,
                                                     [FromRoute] string location,
                                                     PatchAmount patch)
        {
            var inventoryItem = await _inventoryService.GetInventoryItem(grade, company);

            if (inventoryItem == null)
            {
                return(BadRequest());
            }

            var usedAtLocation = inventoryItem.Distribution.SingleOrDefault(used => used.Location == location);

            if (usedAtLocation is null)
            {
                usedAtLocation = new ServantAllocation {
                    Used = 0, Location = location
                };
                inventoryItem.Distribution.Add(usedAtLocation);
            }

            usedAtLocation.Used += patch.Amount;
            if (usedAtLocation.Available < 0 || usedAtLocation.Used < 0)
            {
                return(BadRequest("Can not use more than on stock"));
            }

            await _inventoryService.UpsertInventoryItem(company, grade, inventoryItem);

            await _inventoryService.NewEventJournalEntry(new ServantUsed(grade, company, location, patch.Amount));

            return(Ok());
        }
コード例 #3
0
        public async Task <ActionResult> CorrectMaterialStock(string company, string sapNr, string location,
                                                              PatchAmount newStock)
        {
            var current = await _materialInventoryService.GetInventoryItem(sapNr, company);

            if (current == null)
            {
                return(BadRequest("No inventory available"));
            }

            if (newStock.Amount < 0)
            {
                return(BadRequest("Stock must be a positive value"));
            }

            if (newStock.Amount < current.Used + current.Damaged)
            {
                return(BadRequest(
                           "you are not allowed to correct stock to lower number than (used + damaged) please redistribute"));
            }
            current.Distribution.First(item => item.Location == location).Stock = newStock.Amount;

            await _materialInventoryService.UpsertInventoryItem(company, sapNr, current);

            await _materialInventoryService.NewEventJournalEntry(new StockCorrected(sapNr, company, location,
                                                                                    newStock.Amount));

            return(Ok());
        }
コード例 #4
0
        public async Task <ActionResult> MaterialRepaired([FromRoute] string company, [FromRoute] string location,
                                                          [FromRoute] string sapNr,
                                                          PatchAmount patch)
        {
            var current = await _materialInventoryService.GetInventoryItem(sapNr, company);

            if (current == null)
            {
                return(BadRequest("No inventory available"));
            }

            if (current.Damaged - patch.Amount < 0)
            {
                return(BadRequest("Can not repair more than damaged"));
            }

            current.Distribution.First(item => item.Location == location).Damaged -= patch.Amount;

            await _materialInventoryService.UpsertInventoryItem(company, sapNr, current);

            await _materialInventoryService.NewEventJournalEntry(new MaterialRepaired(sapNr, location, company,
                                                                                      patch.Amount));

            return(Ok());
        }
コード例 #5
0
        public async Task GivenInventoryWithoutAvailablity_WhenCorrectStockToLowerCapacity_ThenReturnsBadRequest()
        {
            var langnau = Location.At("Langnau");

            GivenPuchInventory("Langnau", stock: 5, damaged: 3, used: 2);

            var newStock = PatchAmount.With(2);
            var result   = await _sut.CorrectMaterialStock(CompanyName, PuchSapNr, langnau.Name, newStock);

            result.Should().BeOfType <BadRequestObjectResult>("you are not allowed to correct stock to lower number than (used + damaged) please redistribute");
        }
コード例 #6
0
        public async Task GivenNoIventory_WhenCallCorrectStock_ThenReturnsBadRequest()
        {
            var langnau = Location.At("Langnau");
            var company = Company.With(CompanyName, new List <Location> {
                langnau
            });
            await _materialDispositionContext.Companies.InsertOneAsync(company);

            var newStock = PatchAmount.With(5);
            var result   = await _sut.CorrectMaterialStock(CompanyName, PuchSapNr, langnau.Name, newStock);

            result.Should().BeOfType <BadRequestObjectResult>("you are not allowed to correct stock without initial inventory");
        }
コード例 #7
0
        public async Task <ActionResult> ServantDetached([FromRoute] string company, [FromRoute] string location,
                                                         [FromRoute] Grade grade, PatchAmount patch)
        {
            var current = await _inventoryService.GetInventoryItem(grade, company);

            if (current == null)
            {
                return(BadRequest("No inventory available"));
            }


            if (current.Available - patch.Amount < 0)
            {
                return(BadRequest($"Can not damage more than stock {current.Available} at {company}"));
            }

            current.Distribution.First(item => item.Location == location).Detached += patch.Amount;

            await _inventoryService.UpsertInventoryItem(company, grade, current);

            await _inventoryService.NewEventJournalEntry(new ServantDetached(grade, company, location, patch.Amount));

            return(Ok());
        }
コード例 #8
0
        public async Task <ActionResult> CorrectIdealForCompany(string company, Grade grade, PatchAmount newIdeal)
        {
            var current = await _inventoryService.GetInventoryItem(grade, company);

            if (current == null)
            {
                return(BadRequest("No inventory available"));
            }

            if (newIdeal.Amount < 0)
            {
                return(BadRequest("Ideal must be a positive value"));
            }

            current.Ideal = newIdeal.Amount;
            await _inventoryService.UpsertInventoryItem(company, grade, current);

            await _inventoryService.NewEventJournalEntry(new IdealCorrected(grade, company, newIdeal.Amount));

            return(Ok());
        }