Exemple #1
0
        //public async Task<IActionResult> Edit(int id, [Bind("Id,SupplierId,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Suppliers suppliers)
        public async Task <IActionResult> Edit(int supplierId, [FromForm] SuppliersForUpdate supplier)
        {
            if (supplierId != supplier.SupplierId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _serviceSuppliers.UpdateSupplier(supplier);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await SuppliersExists(supplier.SupplierId) == false)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Details", new { supplierId = supplierId }));
            }
            return(View(supplier));
        }
        public async Task UpdateSupplier(SuppliersForUpdate supplierToUpdate)
        {
            var serializedSupplierToUpdate = JsonConvert.SerializeObject(supplierToUpdate);

            var request = new HttpRequestMessage(HttpMethod.Put,
                                                 $"{apiRoute}/{supplierToUpdate.SupplierId}");

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType));
            request.Content = new StringContent(serializedSupplierToUpdate);
            request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(mediaType);

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();
        }