public async Task <ActionResult <PollutionSource> > PostPollutionSource(PollutionSource pollutionSource) { _context.PollutionSource.Add(pollutionSource); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPollutionSource", new { id = pollutionSource.Id }, pollutionSource)); }
public async Task <IActionResult> PutPollutionSource(int id, PollutionSource pollutionSource) { if (id != pollutionSource.Id) { return(BadRequest()); } _context.Entry(pollutionSource).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PollutionSourceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// GET: PollutionSources/Delete/5 public async Task <IActionResult> Delete(int?id, string SortOrder, string NameFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.NameFilter = NameFilter; if (id == null) { return(NotFound()); } PollutionSource pollutionSource = null; HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/PollutionSources/{id.ToString()}"); if (response.IsSuccessStatusCode) { pollutionSource = await response.Content.ReadAsAsync <PollutionSource>(); } if (pollutionSource == null) { return(NotFound()); } return(View(pollutionSource)); }
public ActionResult <PollutionSource> PostPollutionSource(PollutionSource pollutionSource) { try { gisDb.PollutionSources.Add(pollutionSource); gisDb.SaveChanges(); } catch (Exception e) { return(BadRequest(e.InnerException.Message)); } return(pollutionSource); }
// GET: PollutionSources/Details/5 public async Task <IActionResult> Details(int?id, string SortOrder, string NameFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.NameFilter = NameFilter; if (id == null) { return(NotFound()); } PollutionSource pollutionSource = null; HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/PollutionSources/{id.ToString()}"); if (response.IsSuccessStatusCode) { pollutionSource = await response.Content.ReadAsAsync <PollutionSource>(); } if (pollutionSource == null) { return(NotFound()); } List <Pollutant> pollutants = new List <Pollutant>(); string urlPollutants = "api/Pollutants", routePollutants = ""; HttpResponseMessage responsePollutants = await _HttpApiClient.GetAsync(urlPollutants + routePollutants); if (responsePollutants.IsSuccessStatusCode) { pollutants = await responsePollutants.Content.ReadAsAsync <List <Pollutant> >(); } ViewBag.Pollutants = new SelectList(pollutants.OrderBy(m => m.Name), "Id", "Name"); ViewBag.DateFrom = (DateTime.Now).ToString("yyyy-MM-dd"); ViewBag.TimeFrom = (DateTime.Today).ToString("HH:mm:ss"); ViewBag.DateTo = (DateTime.Now).ToString("yyyy-MM-dd"); ViewBag.TimeTo = (DateTime.Now).ToString("HH:mm:ss"); return(View(pollutionSource)); }
public ActionResult <PollutionSource> PutPollutionSource(string name, PollutionSource pollutionSource) { if (name != pollutionSource.Name) { return(BadRequest("Id cannot be modified!")); } try { gisDb.Entry(pollutionSource).State = EntityState.Modified; gisDb.SaveChanges(); } catch (Exception e) { string error = e.Message; if (e.InnerException != null) { error = e.InnerException.Message; } return(BadRequest(error)); } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,NorthLatitude,EastLongitude")] PollutionSource pollutionSource, string SortOrder, string NameFilter, int?PageSize, int?PageNumber) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.PageNumber = PageNumber; ViewBag.NameFilter = NameFilter; if (id != pollutionSource.Id) { } if (ModelState.IsValid) { //int logNumber = pollutionSource.Number; //decimal logNorthLatitude = pollutionSource.NorthLatitude; //decimal logEastLongitude = pollutionSource.EastLongitude; //DateTime logDateTimeStart = DateTime.Now; //string url = "api/Logs/EditNote", //route = ""; //route += string.IsNullOrEmpty(route) ? "?" : "&"; //route += $"Number={logNumber.ToString()}"; //route += string.IsNullOrEmpty(route) ? "?" : "&"; //route += $"NorthLatitude={logNorthLatitude.ToString()}".Replace(',', '.'); //route += string.IsNullOrEmpty(route) ? "?" : "&"; //route += $"EastLongitude={logEastLongitude.ToString()}".Replace(',', '.'); //route += string.IsNullOrEmpty(route) ? "?" : "&"; //route += $"DateTimeStart={logDateTimeStart.ToString()}"; //HttpResponseMessage responseLog = await _HttpApiClient.PostAsync(url + route, null); HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync( $"api/PollutionSources/{pollutionSource.Id}", pollutionSource); 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(pollutionSource)); } pollutionSource = await response.Content.ReadAsAsync <PollutionSource>(); return(RedirectToAction(nameof(Index), new { SortOrder = ViewBag.SortOrder, PageSize = ViewBag.PageSize, PageNumber = ViewBag.PageNumber, NameFilter = ViewBag.NameFilter })); } return(View(pollutionSource)); }