//public async Task<IActionResult> Create([Bind("Id,TerritoryId,TerritoryDescription,RegionId")] Territories territories)
        public async Task <IActionResult> Create([FromForm] TerritoriesForCreation territory)
        {
            if (ModelState.IsValid)
            {
                await _serviceTerritories.CreateTerritory(territory);

                return(RedirectToAction(nameof(Index)));
            }

            regionsListItems = await Utilities.FillRegionsCollection(_configuration);

            ViewData["Regions"] = regionsListItems;

            return(View(territory));
        }
示例#2
0
        public async Task <TerritoriesForCreation> CreateTerritory(TerritoriesForCreation territoryToCreation)
        {
            var serializedTerritoryToCreation = JsonConvert.SerializeObject(territoryToCreation);

            var request = new HttpRequestMessage(HttpMethod.Post, $"{apiRoute}");

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType));

            request.Content = new StringContent(serializedTerritoryToCreation);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var createdSupplier = JsonConvert.DeserializeObject <TerritoriesForCreation>(content);

            return(createdSupplier);
        }