Пример #1
0
        public bool UpdateProduct(ProductJSON p)
        {
            if (p == null)
            {
                throw new ArgumentNullException("product");
            }

            using (var ctx = new InventoryEntities())
            {
                var product = _context.Product.Single(a => a.Id == p.Id);

                if (product != null)
                {
                    product.Name     = p.Name;
                    product.Category = p.Category;
                    product.Price    = p.Price;

                    int rowsAffected = _context.SaveChanges();

                    return(rowsAffected > 0 ? true : false);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #2
0
        /*
         * {
         *      "Name":"N3",
         *      "Category":"C3",
         *      "Price": 33
         * }
         */
        public async Task <Document> CreateItemAsync([FromBody] object content)
        {
            ProductJSON product = new ProductJSON();

            product = JsonConvert.DeserializeObject <ProductJSON>(content.ToString());

            return(await DocumentDBRepository <ProductJSON> .CreateItemAsync(product));
        }
Пример #3
0
        //api/Product/UpdateItemAsync/?id=ae270000-895a-5dbb-680f-20c68097789d
        //Post Body :

        /*{
         *      "Name":"N11",
         *      "Category":"C11",
         *      "Price": 111
         * }*/
        public async Task <Document> UpdateItemAsync([FromUri] string id, [FromBody] object content)
        {
            ProductJSON product = new ProductJSON();

            product    = JsonConvert.DeserializeObject <ProductJSON>(content.ToString());
            product.Id = id;

            return(await DocumentDBRepository <ProductJSON> .UpdateItemAsync(id, product));
        }
Пример #4
0
        public JsonResult <ProductJSON> GetProducts(int id)
        {
            ProductJSON objProduct = _productBl.GetProduct(id);

            if (objProduct == null)
            {
                objProduct = new ProductJSON();
            }
            return(Json(objProduct));
        }
        public void Update_Product()
        {
            ProductJSON product = new ProductJSON()
            {
                Id       = 2,
                Name     = "N22",//Changed Name
                Category = "P2",
                Price    = 22
            };

            //mockProductRepository.Object.UpdateProduct(product);
            productController.UpdateProduct(product);

            // Verify the change
            //Assert.AreEqual("N22", mockProductRepository.Object.GetProducts()[1].Name);
            Assert.AreEqual("N22", productController.GetProducts()[1].Name);
        }
        public void Add_Product()
        {
            //int productCount = mockProductRepository.Object.GetProducts().Count;
            int productCount = productController.GetProducts().Count;

            Assert.AreEqual(2, productCount);

            //Prepare
            ProductJSON newProduct = GetNewProduct("N3", "C3", 33.55M);

            //Act
            //mockProductRepository.Object.AddProduct(newProduct);
            productController.AddProduct(newProduct);

            //productCount = mockProductRepository.Object.GetProducts().Count;
            productCount = productController.GetProducts().Count;
            //Assert
            Assert.AreEqual(3, productCount);
        }
Пример #7
0
        public HttpResponseMessage PostProduct([FromBody] ProductJSON objProduct)
        {
            int newprodid = 0;

            if (ModelState.IsValid)
            {
                newprodid = _productBl.PostProduct(objProduct);
            }
            HttpResponseMessage response;

            if (newprodid == 0)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.OK, "New Product is created");
            }
            return(response);
        }
Пример #8
0
        public bool AddProduct(ProductJSON product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            Product newProduct = new Product();

            try
            {
                newProduct.Name     = product.Name;
                newProduct.Category = product.Category;
                newProduct.Price    = product.Price;
                _context.Product.Add(newProduct);
                int rowsAffected = _context.SaveChanges();

                return(rowsAffected > 0 ? true : false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #9
0
 //POST:api/Product/UpdateProduct
 public bool UpdateProduct([FromBody] ProductJSON p)
 {
     return(_repository.UpdateProduct(p));
 }
Пример #10
0
 /*
  * {
  *      "Name":"Milk",
  *      "Category":"Dairy",
  *      "Price":44
  * }
  */
 public bool AddProduct([FromBody] ProductJSON product)
 {
     return(_repository.AddProduct(product));
 }