Exemplo n.º 1
0
        public Product UpdateProduct(string sku, UpdateProduct updatedProduct)
        {
            using (var db = new LiteDatabase(@"C:\data\RobNRest.db"))
            {
                var col = db.GetCollection <Product>("products");


                var foundProduct = col.FindOne(p => p.sku == sku);


                if (!string.IsNullOrEmpty(updatedProduct.image))
                {
                    foundProduct.image = updatedProduct.image;
                }
                if (updatedProduct.cost.HasValue)
                {
                    foundProduct.cost = updatedProduct.cost.Value;
                }
                if (!string.IsNullOrEmpty(updatedProduct.description))
                {
                    foundProduct.description = updatedProduct.description;
                }
                if (updatedProduct.price.HasValue)
                {
                    foundProduct.price = updatedProduct.price.Value;
                }
                if (updatedProduct.quantity.HasValue)
                {
                    foundProduct.quantity = updatedProduct.quantity.Value;
                }

                col.Update(foundProduct);
                return(foundProduct);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult UpdateProduct(string sku, [FromBody] UpdateProduct updatedProduct)
        {
            var foundProduct = LiteDB.GetAProduct(sku);

            if (foundProduct == null)
            {
                return(NotFound());
            }

            var returnProduct = LiteDB.UpdateProduct(sku, updatedProduct);

            return(Ok(returnProduct));
        }