public ActionResult Edit(int id, Category_Products cat) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8082/SpringMVC/servlet/"); var putTask = client.PutAsJsonAsync <Category_Products>("UpdateCategory", cat); putTask.Wait(); var ressult = putTask.Result; if (ressult.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View(cat)); } }
public ActionResult Create(Category_Products Cat) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8082/SpringMVC/servlet/"); var postJob = client.PostAsJsonAsync <Category_Products>("AddCategory", Cat); postJob.Wait(); var postResult = postJob.Result; if (postResult.IsSuccessStatusCode) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, "Server error occured. Please contact admin for help!"); // ViewBag.CategoryList= new SelectList(categorys, "idCategory", "nameCategory"); return(View(Cat)); } }
public ActionResult create(Products prod, HttpPostedFileBase file) { prod.image = file.FileName; string idCat = Request.Form["CategoryList"].ToString(); Console.WriteLine(idCat); Category_Products category = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8082/SpringMVC/servlet/"); var responseTask = client.GetAsync("GetCategory/" + idCat); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <Category_Products>(); readTask.Wait(); category = readTask.Result; Console.WriteLine(category); } } prod.category = category; Console.WriteLine(prod.category); using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8082/SpringMVC/servlet/"); var postJob = client.PostAsJsonAsync <Products>("AddProductwithcat", prod); postJob.Wait(); var postResult = postJob.Result; if (postResult.IsSuccessStatusCode) { return(RedirectToAction("ListProducts")); } ModelState.AddModelError(string.Empty, "Server error occured. Please contact admin for help!"); // ViewBag.CategoryList= new SelectList(categorys, "idCategory", "nameCategory"); return(View(prod)); } }
// GET: Category/Edit/5 public ActionResult Edit(int id) { Category_Products cats = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8082/SpringMVC/servlet/"); var responseTask = client.GetAsync("GetCategory/" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <Category_Products>(); readTask.Wait(); cats = readTask.Result; } } return(View(cats)); }