Beispiel #1
0
        public async Task <IActionResult> PutAccountInventory(string materialID, AccountInventoryDTO accountInventoryDTO)
        {
            var accountID = await GetAccountID();

            var accountInventory = await _context.AccountInventories.FindAsync(accountID, materialID);

            accountInventory.Quantity = accountInventoryDTO.Quantity;

            _context.Entry(accountInventory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!AccountInventoryExists(accountID, materialID))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <ActionResult <AccountInventory> > PostAccountInventory(AccountInventoryDTO accountInventoryDTO)
        {
            var accountID = await GetAccountID();

            var accountInventory = _mapper.Map <AccountInventory>(accountInventoryDTO);

            accountInventory.AccountId = accountID;

            _context.AccountInventories.Add(accountInventory);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException) when(AccountInventoryExists(accountInventory.AccountId, accountInventory.MaterialId))
            {
                return(Conflict());
            }

            return(CreatedAtAction(
                       nameof(GetAccountInventory),
                       new { accountID = accountInventory.AccountId, materialID = accountInventory.MaterialId },
                       _mapper.Map <AccountInventoryDTO>(accountInventory)));
        }