コード例 #1
0
        public async Task <IActionResult> UpdateInventory(InventoryData InvenData)
        {
            User user = await _auth.GetUser(this.User.Identity.Name);

            Permissions permissions = await _auth.GetPermissions(user.Id);

            if (permissions.UpdateInventory == false)
            {
                return(Unauthorized());
            }

            Inventory inventory;

            inventory = await _repo.GetInventory(InvenData.Id);

            //probably a much better way to do this
            //possibly something like:
            //PropertyInfo[] properties = inventory.GetType().GetProperties();
            //foreach (PropertyInfo pi in properties)
            inventory.Name        = InvenData.Name;
            inventory.UPC         = InvenData.UPC;
            inventory.Price       = InvenData.Price;
            inventory.Description = InvenData.Description;
            inventory.Quantity    = InvenData.Quantity;
            //inventory.AlertBit = InvenData.AlertBit;

            var updatedInventory = await _repo.UpdateInventory(inventory);

            //Check if this changes the alert status
            await _alert.CheckAlert(updatedInventory.Id, updatedInventory.Quantity);

            //created at root status code
            return(StatusCode(201));
        }