Esempio n. 1
0
    public async Task <ActionResult> Edit(int id, [Bind] EditModelForm formulaire)
    {
        if (ModelState.IsValid)
        {
            Model model = new Model
            {
                IdModel = id,
                IdBrand = Convert.ToInt32(formulaire.BrandName),
                Name    = formulaire.Name
            };

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

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

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

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

        return(RedirectToAction("Index"));
    }
    else
    {
        return(View());
    }
}
Esempio n. 2
0
    // GET: Model/Edit/5
    public async Task <ActionResult> Edit(string id)
    {
        List <SelectListItem> getbrandformList = new List <SelectListItem>();
        List <GetBrandForm>   getbrandList     = await BrandController.GetBrandList();

        EditModelForm model = new EditModelForm();

        model = await GetDetails(id);

        foreach (GetBrandForm Brand in getbrandList)
        {
            getbrandformList.Add(new SelectListItem {
                    Text = Brand.Name, Value = Brand.IdBrand.ToString()
                }
                                 );
        }

        model.BrandList = getbrandformList;
        return(View(model));
    }
Esempio n. 3
0
        public async Task <EditModelForm> GetDetails(string id)
        {
            Model         ModelGlobal = default(Model);
            EditModelForm ModelLocal  = default(EditModelForm);

            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, EditModelForm> .AutoMap(ModelGlobal);
                }
            }

            return(ModelLocal);
        }