// GET: Resource/Details/5 public ActionResult Details(int id) { ResourceViewModelDetails r = new ResourceViewModelDetails(); HttpClient Client = new HttpClient(); Client.BaseAddress = new Uri("http://localhost:18080"); Client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = Client.GetAsync("InfinityMAP-web/rest/ResourceService/detailsResources/" + id).Result; HttpResponseMessage response1 = Client.GetAsync("InfinityMAP-web/rest/ResourceRequestService/getResourceRequest").Result; if (response.IsSuccessStatusCode) { r = response.Content.ReadAsAsync <ResourceViewModelDetails>().Result; } if (response1.IsSuccessStatusCode) { ViewBag.result = response1.Content.ReadAsAsync <IEnumerable <ResourceRequestViewModel> >().Result; ViewBag.number = rrs.GetresourceRequestNumber(); } else { ViewBag.result = "erreur"; } return(View(r)); }
public ActionResult Filter(ResourceViewModelDetails rv) { string url = "/InfinityMAP-web/rest/ResourceService/filterResources"; if (rv.firstname != "") { url = url + "&firstname=" + rv.firstname; } else { Console.WriteLine("prenom null"); } if (rv.lastname != "") { url = url + "&lastname=" + rv.lastname; } else { Console.WriteLine("nom null"); } HttpClient Client = new HttpClient(); Client.BaseAddress = new Uri("http://localhost:18080"); Client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = Client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { ViewBag.result = response.Content.ReadAsAsync <ResourceViewModel>().Result; } else { ViewBag.result = "erreur"; } return(View()); }
public ActionResult Edit(int id, ResourceViewModelDetails rd, HttpPostedFileBase ImageFile) { ResourceViewModelDetails r = new ResourceViewModelDetails(); r.id = rd.id; r.lastname = rd.lastname; r.firstname = rd.firstname; r.profil = rd.profil; r.region = rd.region; r.sector = rd.sector; r.state = rd.state; r.seniority = rd.seniority; r.contractype = rd.contractype; if (ImageFile != null) { string filename = Path.GetFileName(ImageFile.FileName); string path = Path.Combine(Server.MapPath("~/Image"), filename); ImageFile.SaveAs(path); r.picture = filename; } object data = new { lastname = r.lastname, firstname = r.firstname, profil = r.profil, region = r.region, sector = r.sector, state = r.state, seniority = r.seniority, contractype = r.contractype, picture = r.picture, }; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:18080"); var myContent = JsonConvert.SerializeObject(data); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client .PutAsJsonAsync("InfinityMAP-web/rest/ResourceService/updateResource/" + id, r).Result; if (response.IsSuccessStatusCode) { // Get the URI of the created resource. Console.WriteLine("modifie"); } else { ViewBag.result = "error"; } return(RedirectToAction("Index")); } catch { return(View()); } }