public async Task <ObjectAPI> UpdateLocation([FromBody] Location_Tracking location) { ObjectAPI obj = new ObjectAPI(); var rel = await localServices.UpdateLocation(location); obj.Data = rel; if (rel) { obj.Message = "Thành công!"; obj.Success = true; obj.StatusCode = "200"; } else { obj.Message = "Thất bại"; obj.StatusCode = "404"; obj.Success = false; } return(obj); }
public async Task <bool> UpdateLocation(Location_Tracking location) { bool rel = true; if (location != null) { var local = await db.Location_Tracking .Where(n => n.NVID.Equals(location.NVID) && int.Parse(n.GioBD) < DateTime.Now.Hour && int.Parse(n.GioKT) > DateTime.Now.Hour && n.DateTracking.Value.Date.ToString("d").Equals(DateTime.Now.Date.ToString("d"))).FirstOrDefaultAsync(); if (local == null) { location.GioBD = DateTime.Now.Hour.ToString(); location.GioKT = (DateTime.Now.Hour + 1).ToString(); location.NguoiTao = location.NVID.ToString(); location.NgayTao = DateTime.Now; location.DateTracking = DateTime.Now; db.Location_Tracking.Add(location); await db.SaveChangesAsync(); } else { local.NgaySua = DateTime.Now; local.NguoiSua = location.NVID.ToString(); local.GhiChu = location.GhiChu; db.Entry(local).State = EntityState.Modified; await db.SaveChangesAsync(); } } else { rel = false; } return(rel); }