Exemple #1
0
        public async Task <ActionResult> Create([Bind] AddModelForm formulaire)
        {
            if (ModelState.IsValid)
            {
                Model model = new Model
                {
                    IdBrand = Convert.ToInt32(formulaire.BrandName),
                    Name    = formulaire.Name
                };

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    client.DefaultRequestHeaders.Clear();
                    //HTTP POST
                    StringContent content = new StringContent(JsonConvert.SerializeObject(model));
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    HttpResponseMessage Res = await client.PostAsync($"Model/Create", content);

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

            return(RedirectToAction("Index"));
        }
        else
        {
            return(View(formulaire));
        }
    }
Exemple #2
0
        // GET: Model/Create
        public async Task <ActionResult> Create()
        {
            List <SelectListItem> getbrandformList = new List <SelectListItem>();
            List <GetBrandForm>   getbrandList     = await BrandController.GetBrandList();

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

            var model = new AddModelForm
            {
                BrandList = getbrandformList
            };

            return(View(model));
        }