コード例 #1
0
        //update
        public void Update(ProductModel Productdata)
        {
            var request = new RestRequest("api/Product", Method.PUT) { RequestFormat = DataFormat.Json };
            request.AddParameter("id", Productdata.ProductId, ParameterType.UrlSegment);

            var responce = _client.Execute<ProductModel>(request);

            if (responce.StatusCode != HttpStatusCode.NotFound)
                throw new Exception(responce.ErrorMessage);
        }
コード例 #2
0
        //Add
        public void Add(ProductModel Productdata)
        {
            var request = new RestRequest("api/Product", Method.POST) { RequestFormat = DataFormat.Json };
            request.AddBody(Productdata);

            var responce = _client.Execute<ProductModel>(request);

            if (responce.StatusCode != HttpStatusCode.Created)
                throw new Exception(responce.ErrorMessage);
        }
コード例 #3
0
 public ActionResult Edit(ProductModel productData)
 {
     try
     {
         RestClient.Update(productData);
         return RedirectToAction("Index");
     }
     catch
     {
         
        return View();
     }
 }
コード例 #4
0
        public ActionResult Delete(ProductModel productData)
        {
            try
            {
                RestClient.Delete(productData.ProductId);
                return RedirectToAction("Index");

            }
            catch 
            {

                return View();

            }

        }
コード例 #5
0
        public ActionResult Create(ProductModel productData)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    RestClient.Add(productData);
                    return RedirectToAction("Index");
                }
                return View(productData);
                
            }
            catch 
            {

                return View();
            }
        }