public async Task <bool> UpdateLocation(CurrentLocationTracking clt) { if (clt == null) { return(false); } var cur = await db.CurrentLocationTrackings.Where(n => n.NVID.Equals(clt.NVID)).FirstOrDefaultAsync(); if (cur != null) { cur.KinhDo = clt.KinhDo; cur.ViDo = clt.ViDo; cur.NgaySua = DateTime.Now; cur.NguoiSua = cur.NVID.ToString(); db.Entry(cur).State = EntityState.Modified; } else { cur.NguoiTao = cur.NVID.ToString(); cur.NgayTao = DateTime.Now; db.CurrentLocationTrackings.Add(clt); } await db.SaveChangesAsync(); return(true); }
public async Task <IHttpActionResult> PostCurrentLocationTracking([FromBody] CurrentLocationTracking currentLocationTracking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CurrentLocationTrackings.Add(currentLocationTracking); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CurrentLocationTrackingExists(currentLocationTracking.NVID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = currentLocationTracking.NVID }, currentLocationTracking)); }
public async Task <IHttpActionResult> PutCurrentLocationTracking(Guid id, [FromBody] CurrentLocationTracking currentLocationTracking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != currentLocationTracking.NVID) { return(BadRequest()); } db.Entry(currentLocationTracking).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CurrentLocationTrackingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetCurrentLocationTracking(Guid id) { CurrentLocationTracking currentLocationTracking = await db.CurrentLocationTrackings.FindAsync(id); if (currentLocationTracking == null) { return(NotFound()); } return(Ok(currentLocationTracking)); }
public async Task <IHttpActionResult> DeleteCurrentLocationTracking(Guid id) { CurrentLocationTracking currentLocationTracking = await db.CurrentLocationTrackings.FindAsync(id); if (currentLocationTracking == null) { return(NotFound()); } db.CurrentLocationTrackings.Remove(currentLocationTracking); await db.SaveChangesAsync(); return(Ok(currentLocationTracking)); }