public async Task <ActionResult <FunModel> > UpdateFun(int id, FunModel funModel) { if (id != funModel.FunId) { return(BadRequest()); } _context.Entry(funModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FunExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <FunModel> > SaveFun(FunModel funModel) { _context.FunModel.Add(funModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFun", new { id = funModel.FunId }, funModel)); }
public async Task<IActionResult> FunDelete(int Id) { var fun = new FunModel(); HttpClient client = _funApi.Initial(); HttpResponseMessage res = await client.DeleteAsync($"api/funapi/{Id}"); return RedirectToAction("funindex"); }
public async Task<IActionResult> FunDetails(int Id) { var fun = new FunModel(); HttpClient client = _funApi.Initial(); HttpResponseMessage res = await client.GetAsync($"api/funapi/{Id}"); if (res.IsSuccessStatusCode) { var results = res.Content.ReadAsStringAsync().Result; fun = JsonConvert.DeserializeObject<FunModel>(results); } return View(fun); }
public async Task<FunModel> FunEdit(FunModel fun) { HttpClient client = _funApi.Initial(); HttpResponseMessage response = await client.PutAsJsonAsync( $"api/funapi/{fun.FunId}", fun); response.EnsureSuccessStatusCode(); fun = await response.Content.ReadAsAsync<FunModel>(); return fun; }
public IActionResult FunCreate(FunModel fun) { HttpClient client = _funApi.Initial(); //HTTP POST var postTask = client.PostAsJsonAsync<FunModel>("api/funapi", fun); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return RedirectToAction("funindex"); } return View(fun); }