コード例 #1
0
// GET: Model/Delete/5
public async Task <ActionResult> Delete(int id)
{
    List <GetBrandForm> getbrandList = await BrandController.GetBrandList();

    Model           ModelGlobal = default(Model);
    DeleteModelForm ModelLocal  = default(DeleteModelForm);

    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($"Model/Get/{id}");

        if (Res.IsSuccessStatusCode)
        {
            var EmpResponse = Res.Content.ReadAsStringAsync().Result;
            ModelGlobal = JsonConvert.DeserializeObject <Model>(EmpResponse);
            ModelLocal  = AutoMapper <Model, DeleteModelForm> .AutoMap(ModelGlobal);
        }
    }

    ModelLocal.BrandName = (from b in getbrandList
                            where b.IdBrand == ModelLocal.IdBrand
                            select b.Name).FirstOrDefault();

    return(View(ModelLocal));
}
コード例 #2
0
public async Task <ActionResult> Delete(int id, [Bind] DeleteModelForm formulaire)
{
    if (ModelState.IsValid)
    {
        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.DeleteAsync($"Model/Delete/{id}");

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

        return(RedirectToAction("Index"));
    }
    else
    {
        return(View());
    }
}