// GET: Scotches/Edit/1 public async Task <IActionResult> Edit(string id) { if (id == null) { return(NotFound()); } ScotchDTO dto = new ScotchDTO(); HttpClient client = _scotchesAPI.InitializeClient(); HttpResponseMessage res = await client.GetAsync("/api/scotches/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; dto = JsonConvert.DeserializeObject <ScotchDTO>(result); } //var WishList = dto.SingleOrDefault(m => m.wishListName == wishListName); if (dto == null) { return(NotFound()); } return(View(dto)); }
public IActionResult Create([Bind("distillerName,flavor,age,style,region,inStock,bottlingNotes,comment")] ScotchDTO Scotch) { if (ModelState.IsValid) { HttpClient client = _scotchesAPI.InitializeClient(); var content = new StringContent(JsonConvert.SerializeObject(Scotch, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json"); HttpResponseMessage res = client.PostAsync("/api/scotches", content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(Scotch)); }
public IActionResult Edit(string id, [Bind("distillerName,flavor,age,style,region,inStock,bottlingNotes,comment,_id")] ScotchDTO Scotch) { if (id != Scotch._id) { return(NotFound()); } if (ModelState.IsValid) { HttpClient client = _scotchesAPI.InitializeClient(); var content = new StringContent(JsonConvert.SerializeObject(Scotch), Encoding.UTF8, "application/json"); HttpResponseMessage res = client.PutAsync("/api/scotches/" + id, content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(Scotch)); }