Exemplo n.º 1
0
        public async Task <EditSellerForm> GetDetails(string id)
        {
            Seller         ModelGlobal = default(Seller);
            EditSellerForm ModelLocal  = default(EditSellerForm);

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

                if (Res.IsSuccessStatusCode)
                {
                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    ModelGlobal = JsonConvert.DeserializeObject <Seller>(EmpResponse);
                    ModelLocal  = AutoMapper <Seller, EditSellerForm> .AutoMap(ModelGlobal);
                }
            }
            return(ModelLocal);
        }
Exemplo n.º 2
0
    public async Task <ActionResult> Edit(int id, [Bind] EditSellerForm formulaire)
    {
        if (ModelState.IsValid)
        {
            Seller seller = new Seller
            {
                IdSeller = id,
                Name     = formulaire.Name,
                Tva      = formulaire.Tva,
                Email    = formulaire.Email,
                Phone    = formulaire.Phone,
                Street   = formulaire.Street,
                Number   = formulaire.Number,
                Zip      = formulaire.Zip,
                Locality = formulaire.Locality,
                Country  = formulaire.Country,
                Account  = formulaire.Account
            };
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();

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

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

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

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