private data.AspNetRoles GetById(int?id) { data.AspNetRoles aux = new data.AspNetRoles(); using (var cl = new HttpClient()) { cl.BaseAddress = new Uri(baseurl); cl.DefaultRequestHeaders.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage res = cl.GetAsync("api/AspNetRoles/" + id).Result; if (res.IsSuccessStatusCode) { var auxres = res.Content.ReadAsStringAsync().Result; aux = JsonConvert.DeserializeObject <data.AspNetRoles>(auxres); } } return(aux); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,NormalizedName,ConcurrencyStamp")] data.AspNetRoles aspNetRoles) { if (id != Convert.ToInt32(aspNetRoles.Id)) { return(NotFound()); } if (ModelState.IsValid) { try { using (var cl = new HttpClient()) { cl.BaseAddress = new Uri(baseurl); var content = JsonConvert.SerializeObject(aspNetRoles); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var postTask = cl.PutAsync("api/AspNetRoles/" + id, byteContent).Result; if (postTask.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } } catch (Exception) { var aux2 = GetById(id); if (aux2 == null) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(aspNetRoles)); }
public async Task <IActionResult> Create([Bind("Id,Name,NormalizedName,ConcurrencyStamp")] data.AspNetRoles aspNetRoles) { if (ModelState.IsValid) { using (var cl = new HttpClient()) { cl.BaseAddress = new Uri(baseurl); var content = JsonConvert.SerializeObject(aspNetRoles); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var postTask = cl.PostAsync("api/AspNetRoles", byteContent).Result; if (postTask.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } } } return(View(aspNetRoles)); }