//public async Task<IActionResult> Edit(int id, [Bind("Id,TerritoryId,TerritoryDescription,RegionId")] Territories territories)
        public async Task <IActionResult> Edit(string territoryId, [FromForm] TerritoriesForUpdate territory)
        {
            if (territoryId != territory.TerritoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _serviceTerritories.UpdateTerritory(territory);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await TerritoriesExists(territory.TerritoryId) == false)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Details", new { territoryId = territoryId }));
            }
            //ViewData["RegionId"] = new SelectList(_context.Region, "Id", "Id", territories.RegionId);
            return(View(territory));
        }
Example #2
0
        public async Task UpdateTerritory(TerritoriesForUpdate territoryToUpdate)
        {
            var serializedTerritoryToUpdate = JsonConvert.SerializeObject(territoryToUpdate);

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

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

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();
        }