Пример #1
0
        public int UpdateAmountInStock(Product _product, int _amount)
        {
            string query = "DECLARE @Difference int SET @Difference = (SELECT AmountInStock FROM Product WHERE ID = @ProductID) + @AmountDelivered IF @Difference < 0 SET @AmountDelivered = @AmountDelivered - @Difference; UPDATE Product SET AmountInStock = AmountInStock + @AmountDelivered WHERE ID = @ProductID SELECT @AmountDelivered AS 'Result'";
            List <KeyValuePair <string, object> > parameterlist = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>("@AmountDelivered", _amount),
                new KeyValuePair <string, object>("@ProductID", _product.ID)
            };

            return(SQL_CRUD_Methods.SQLUpdateReturnInt(query, parameterlist));
        }