public async Task <IHttpActionResult> Put(int id, [FromBody] GpsTag gpsTrack) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != gpsTrack.Id) { return(BadRequest()); } db.Entry(gpsTrack).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GpsTrackExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Get(int id) { GpsTag gpsTrack = await db.GpsTracks.FindAsync(id); if (gpsTrack == null) { return(NotFound()); } return(Ok(gpsTrack)); }
public async Task <IHttpActionResult> Delete(int id) { GpsTag gpsTrack = await db.GpsTracks.FindAsync(id); if (gpsTrack == null) { return(NotFound()); } db.GpsTracks.Remove(gpsTrack); await db.SaveChangesAsync(); return(Ok(gpsTrack)); }
public async Task <IActionResult> GetArticle(int latitudeSeconds, int longitudeSeconds) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if ((Math.Abs(latitudeSeconds) > MaxLatitudeSeconds) || (Math.Abs(longitudeSeconds) > MaxLongitudeSeconds)) { return(BadRequest("Not existing place")); } GpsTag nearestGpsTag = await _context.GpsTags .OrderBy((tag) => Math.Sqrt(Math.Pow(GetNormalizedLatitudeDistance(latitudeSeconds, tag.LatitudeSeconds), 2) + Math.Pow(GetNormalizedLongitudeDistance(longitudeSeconds, tag.LongitudeSeconds), 2))) .FirstOrDefaultAsync(); var articles = nearestGpsTag == null ? null : _context.ArticlesGpsTags.Where((agt) => agt.TagId == nearestGpsTag.TagId).Select((agt) => new ArticleDto(agt.Article)); return(Ok(articles == null ? Array.Empty <ArticleDto>() : await articles.ToArrayAsync())); }
public GpsTagDto(GpsTag tag) { LatitudeSeconds = tag?.LatitudeSeconds; LongitudeSeconds = tag?.LongitudeSeconds; }