// GET: SpeciallyProtectedNaturalTerritories/Delete/5
        public async Task <IActionResult> Delete(int?id,
                                                 string SortOrder,
                                                 string NameENFilter,
                                                 string NameRUFilter,
                                                 string NameKKFilter,
                                                 int?AuthorizedAuthorityIdFilter,
                                                 int?PageSize,
                                                 int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.NameENFilter = NameENFilter;
            ViewBag.NameRUFilter = NameRUFilter;
            ViewBag.NameKKFilter = NameKKFilter;
            ViewBag.AuthorizedAuthorityIdFilter = AuthorizedAuthorityIdFilter;
            if (id == null)
            {
                return(NotFound());
            }

            SpeciallyProtectedNaturalTerritory speciallyProtectedNaturalTerritory = null;
            HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/SpeciallyProtectedNaturalTerritories/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                speciallyProtectedNaturalTerritory = await response.Content.ReadAsAsync <SpeciallyProtectedNaturalTerritory>();
            }
            if (speciallyProtectedNaturalTerritory == null)
            {
                return(NotFound());
            }

            return(View(speciallyProtectedNaturalTerritory));
        }
        // GET: SpeciallyProtectedNaturalTerritories/Edit/5
        public async Task <IActionResult> Edit(int?id,
                                               string SortOrder,
                                               string NameENFilter,
                                               string NameRUFilter,
                                               string NameKKFilter,
                                               int?AuthorizedAuthorityIdFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.NameENFilter = NameENFilter;
            ViewBag.NameRUFilter = NameRUFilter;
            ViewBag.NameKKFilter = NameKKFilter;
            ViewBag.AuthorizedAuthorityIdFilter = AuthorizedAuthorityIdFilter;
            SpeciallyProtectedNaturalTerritory speciallyProtectedNaturalTerritory = null;
            HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/SpeciallyProtectedNaturalTerritories/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                speciallyProtectedNaturalTerritory = await response.Content.ReadAsAsync <SpeciallyProtectedNaturalTerritory>();
            }

            List <AuthorizedAuthority> authorizedAuthorities = new List <AuthorizedAuthority>();
            string urlAuthorizedAuthorities   = "api/AuthorizedAuthorities",
                   routeAuthorizedAuthorities = "";
            HttpResponseMessage responseAuthorizedAuthorities = await _HttpApiClient.GetAsync(urlAuthorizedAuthorities + routeAuthorizedAuthorities);

            if (responseAuthorizedAuthorities.IsSuccessStatusCode)
            {
                authorizedAuthorities = await responseAuthorizedAuthorities.Content.ReadAsAsync <List <AuthorizedAuthority> >();
            }
            ViewBag.AuthorizedAuthorities = new SelectList(authorizedAuthorities.OrderBy(m => m.Name), "Id", "Name", speciallyProtectedNaturalTerritory.AuthorizedAuthorityId);

            return(View(speciallyProtectedNaturalTerritory));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,NameKK,NameRU,NameEN,AuthorizedAuthorityId,Areahectares")] SpeciallyProtectedNaturalTerritory speciallyProtectedNaturalTerritory,
                                               string SortOrder,
                                               string NameENFilter,
                                               string NameRUFilter,
                                               string NameKKFilter,
                                               int?AuthorizedAuthorityIdFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder    = SortOrder;
            ViewBag.PageSize     = PageSize;
            ViewBag.PageNumber   = PageNumber;
            ViewBag.NameENFilter = NameENFilter;
            ViewBag.NameRUFilter = NameRUFilter;
            ViewBag.NameKKFilter = NameKKFilter;
            ViewBag.AuthorizedAuthorityIdFilter = AuthorizedAuthorityIdFilter;
            if (id != speciallyProtectedNaturalTerritory.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync(
                    $"api/SpeciallyProtectedNaturalTerritories/{speciallyProtectedNaturalTerritory.Id}", speciallyProtectedNaturalTerritory);

                string OutputViewText = await response.Content.ReadAsStringAsync();

                OutputViewText = OutputViewText.Replace("<br>", Environment.NewLine);
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch
                {
                    dynamic errors = JsonConvert.DeserializeObject <dynamic>(OutputViewText);
                    foreach (Newtonsoft.Json.Linq.JProperty property in errors.Children())
                    {
                        ModelState.AddModelError(property.Name, property.Value[0].ToString());
                    }
                    return(View(speciallyProtectedNaturalTerritory));
                }

                speciallyProtectedNaturalTerritory = await response.Content.ReadAsAsync <SpeciallyProtectedNaturalTerritory>();

                return(RedirectToAction(nameof(Index),
                                        new
                {
                    SortOrder = ViewBag.SortOrder,
                    PageSize = ViewBag.PageSize,
                    PageNumber = ViewBag.PageNumber,
                    NameENFilter = ViewBag.NameENFilter,
                    NameRUFilter = ViewBag.NameRUFilter,
                    NameKKFilter = ViewBag.NameKKFilter,
                    AuthorizedAuthorityIdFilter = ViewBag.AuthorizedAuthorityIdFilter
                }));
            }

            List <AuthorizedAuthority> authorizedAuthorities = new List <AuthorizedAuthority>();
            string urlAuthorizedAuthorities   = "api/AuthorizedAuthorities",
                   routeAuthorizedAuthorities = "";
            HttpResponseMessage responseAuthorizedAuthorities = await _HttpApiClient.GetAsync(urlAuthorizedAuthorities + routeAuthorizedAuthorities);

            if (responseAuthorizedAuthorities.IsSuccessStatusCode)
            {
                authorizedAuthorities = await responseAuthorizedAuthorities.Content.ReadAsAsync <List <AuthorizedAuthority> >();
            }
            ViewBag.AuthorizedAuthorities = new SelectList(authorizedAuthorities.OrderBy(m => m.Name), "Id", "Name", speciallyProtectedNaturalTerritory.AuthorizedAuthorityId);

            return(View(speciallyProtectedNaturalTerritory));
        }
        public async Task <ActionResult <SpeciallyProtectedNaturalTerritory> > PostSpeciallyProtectedNaturalTerritory(SpeciallyProtectedNaturalTerritory speciallyProtectedNaturalTerritory)
        {
            _context.SpeciallyProtectedNaturalTerritory.Add(speciallyProtectedNaturalTerritory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSpeciallyProtectedNaturalTerritory", new { id = speciallyProtectedNaturalTerritory.Id }, speciallyProtectedNaturalTerritory));
        }
        public async Task <IActionResult> PutSpeciallyProtectedNaturalTerritory(int id, SpeciallyProtectedNaturalTerritory speciallyProtectedNaturalTerritory)
        {
            if (id != speciallyProtectedNaturalTerritory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(speciallyProtectedNaturalTerritory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpeciallyProtectedNaturalTerritoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }