//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);
        }
        //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);
        }
Exemple #3
0
 public ActionResult Edit(ProductModel productData)
 {
     try
     {
         RestClient.Update(productData);
         return RedirectToAction("Index");
     }
     catch
     {
         
        return View();
     }
 }
Exemple #4
0
        public ActionResult Delete(ProductModel productData)
        {
            try
            {
                RestClient.Delete(productData.ProductId);
                return RedirectToAction("Index");

            }
            catch 
            {

                return View();

            }

        }
Exemple #5
0
        public ActionResult Create(ProductModel productData)
        {
            try
            {
                if (ModelState.IsValid)
                {

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

                return View();
            }
        }