// GET: SpeciesDiversities/Delete/5 public async Task <IActionResult> Delete(int?id, string SortOrder, int?KATOIdFilter, int?PlantationsTypeIdFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.KATOIdFilter = KATOIdFilter; ViewBag.PlantationsTypeIdFilter = PlantationsTypeIdFilter; if (id == null) { return(NotFound()); } SpeciesDiversity speciesDiversity = null; HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/SpeciesDiversities/{id.ToString()}"); if (response.IsSuccessStatusCode) { speciesDiversity = await response.Content.ReadAsAsync <SpeciesDiversity>(); } if (speciesDiversity == null) { return(NotFound()); } return(View(speciesDiversity)); }
public async Task <IActionResult> PutSpeciesDiversity(int id, SpeciesDiversity speciesDiversity) { if (id != speciesDiversity.Id) { return(BadRequest()); } _context.Entry(speciesDiversity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpeciesDiversityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <SpeciesDiversity> > PostSpeciesDiversity(SpeciesDiversity speciesDiversity) { _context.SpeciesDiversity.Add(speciesDiversity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSpeciesDiversity", new { id = speciesDiversity.Id }, speciesDiversity)); }
// GET: SpeciesDiversities/Edit/5 public async Task <IActionResult> Edit(int?id, string SortOrder, int?KATOIdFilter, int?PlantationsTypeIdFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.KATOIdFilter = KATOIdFilter; ViewBag.PlantationsTypeIdFilter = PlantationsTypeIdFilter; SpeciesDiversity speciesDiversity = null; HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/SpeciesDiversities/{id.ToString()}"); if (response.IsSuccessStatusCode) { speciesDiversity = await response.Content.ReadAsAsync <SpeciesDiversity>(); } List <KATO> KATOes = new List <KATO>(); string urlKATOes = "api/KATOes", routeKATOes = ""; HttpResponseMessage responseKATOes = await _HttpApiClient.GetAsync(urlKATOes + routeKATOes); if (responseKATOes.IsSuccessStatusCode) { KATOes = await responseKATOes.Content.ReadAsAsync <List <KATO> >(); } ViewBag.KATOes = new SelectList(KATOes.Where(k => k.ParentEgovId == 17112).OrderBy(m => m.Name), "Id", "Name", speciesDiversity.KATOId); List <PlantationsType> plantationsTypes = new List <PlantationsType>(); string urlPlantationsTypes = "api/PlantationsTypes", routePlantationsTypes = ""; HttpResponseMessage responsePlantationsTypes = await _HttpApiClient.GetAsync(urlPlantationsTypes + routePlantationsTypes); if (responsePlantationsTypes.IsSuccessStatusCode) { plantationsTypes = await responsePlantationsTypes.Content.ReadAsAsync <List <PlantationsType> >(); } ViewBag.PlantationsTypes = new SelectList(plantationsTypes.OrderBy(m => m.Name), "Id", "Name", speciesDiversity.PlantationsTypeId); return(View(speciesDiversity)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,KATOId,PlantationsTypeId,TreesNumber")] SpeciesDiversity speciesDiversity, string SortOrder, int?KATOIdFilter, int?PlantationsTypeIdFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.KATOIdFilter = KATOIdFilter; ViewBag.PlantationsTypeIdFilter = PlantationsTypeIdFilter; if (id != speciesDiversity.Id) { return(NotFound()); } if (ModelState.IsValid) { HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync( $"api/SpeciesDiversities/{speciesDiversity.Id}", speciesDiversity); 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(speciesDiversity)); } speciesDiversity = await response.Content.ReadAsAsync <SpeciesDiversity>(); return(RedirectToAction(nameof(Index), new { SortOrder = ViewBag.SortOrder, PageSize = ViewBag.PageSize, PageNumber = ViewBag.PageNumber, KATOIdFilter = ViewBag.KATOIdFilter, PlantationsTypeIdFilter = ViewBag.PlantationsTypeIdFilter })); } List <KATO> KATOes = new List <KATO>(); string urlKATOes = "api/KATOes", routeKATOes = ""; HttpResponseMessage responseKATOes = await _HttpApiClient.GetAsync(urlKATOes + routeKATOes); if (responseKATOes.IsSuccessStatusCode) { KATOes = await responseKATOes.Content.ReadAsAsync <List <KATO> >(); } ViewBag.KATOes = new SelectList(KATOes.Where(k => k.ParentEgovId == 17112).OrderBy(m => m.Name), "Id", "Name", speciesDiversity.KATOId); List <PlantationsType> plantationsTypes = new List <PlantationsType>(); string urlPlantationsTypes = "api/PlantationsTypes", routePlantationsTypes = ""; HttpResponseMessage responsePlantationsTypes = await _HttpApiClient.GetAsync(urlPlantationsTypes + routePlantationsTypes); if (responsePlantationsTypes.IsSuccessStatusCode) { plantationsTypes = await responsePlantationsTypes.Content.ReadAsAsync <List <PlantationsType> >(); } ViewBag.PlantationsTypes = new SelectList(plantationsTypes.OrderBy(m => m.Name), "Id", "Name", speciesDiversity.PlantationsTypeId); return(View(speciesDiversity)); }