public async Task <ActionResult> UpdateList([Bind(Include = "Id,Name")] Models.Api.List list) { if (ModelState.IsValid) { var updated = await _listsService.UpdateList(list); return(RedirectToAction("Index", new { list = list.Id })); // todo: handle errors, show success messages, etc } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] Models.Api.List list) { if (ModelState.IsValid) { await _listsService.UpdateList(list); return(RedirectToAction("Index")); } return(View(list)); }
public async Task <bool> UpdateList(Models.Api.List list) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var json = JsonConvert.SerializeObject(list); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PutAsync(ListsResource + $"/{list.Id}", content); return(response.IsSuccessStatusCode); } }
public async Task <ActionResult> Create([Bind(Include = "Name")] Models.Api.List list) { if (ModelState.IsValid) { var result = await _listsService.CreateList(list); if (result.success) { return(RedirectToAction("Index", "Home", new { list = result.newListId })); } } return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Update([Bind(Include = "Id,Name")] Models.Api.List list) { if (ModelState.IsValid) { var existingList = await _listsService.GetList(list.Id); //Inlcudes all tasks which we are not changing if (existingList != null) { existingList.Name = list.Name; await _listsService.UpdateList(existingList); return(RedirectToAction("Index", "Home", new { list = existingList.Id })); } } return(RedirectToAction("Index", "Home")); }
public async Task <Models.Api.List> GetList(string Id) { Models.Api.List lst = null; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(ListsResource + $"/{Id}"); if (response.IsSuccessStatusCode) { var stringContent = await response.Content.ReadAsStringAsync(); lst = JsonConvert.DeserializeObject <Models.Api.List>(stringContent); } } return(lst); }
public async Task <(bool success, string newListId)> CreateList(Models.Api.List list) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var json = JsonConvert.SerializeObject(list); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(ListsResource, content); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); var outputList = JsonConvert.DeserializeObject <Models.Api.List>(responseString); return(success : true, newListId : outputList.Id); } else { return(success : false, newListId : ""); } } }