コード例 #1
0
    public async Task <ActionResult> Edit(int id, EditEquipementForm formulaire)
    {
        if (ModelState.IsValid)
        {
            Equipement equip = new Equipement
            {
                IdEquipement = formulaire.IdEquipement,
                Name         = formulaire.Name,
                Description  = formulaire.Description
            };

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();

                StringContent content = new StringContent(JsonConvert.SerializeObject(equip));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage Res = await client.PutAsync($"Equipment/Update", content);

                if (!Res.IsSuccessStatusCode)       /*error handling*/
                {
                }
            }

            return(RedirectToAction("Index"));
        }
        else
        {
            return(View());
        }
    }
コード例 #2
0
        public async Task <EditEquipementForm> GetDetails(string id)
        {
            Equipement         ModelGlobal = default(Equipement);
            EditEquipementForm ModelLocal  = default(EditEquipementForm);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage Res = await client.GetAsync($"Equipment/Get/{id}");

                if (Res.IsSuccessStatusCode)
                {
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;

                    ModelGlobal = JsonConvert.DeserializeObject <Equipement>(EmpResponse);
                    ModelLocal  = AutoMapper <Equipement, EditEquipementForm> .AutoMap(ModelGlobal);
                }
            }
            return(ModelLocal);
        }