public IActionResult Update([FromBody] DefenseDevice device) { if (device == null) { return(BadRequest("DefenseDevice object can not be null!")); } using (var db = new AllInOneContext.AllInOneContext()) { try { db.DefenseDevice.Update(device); db.SaveChanges(); return(NoContent()); } catch (DbUpdateException dbEx) { _logger.LogError("更新防区设备异常:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (Exception ex) { _logger.LogError("更新防区设备异常:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } } }
public IActionResult GetById(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { DefenseDevice obj = GetQuery(db).FirstOrDefault(t => t.DefenseDeviceId.Equals(id)); if (obj == null) { return(NotFound()); } return(new ObjectResult(obj)); } }
public IActionResult Delete(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { DefenseDevice deleteObj = db.DefenseDevice.FirstOrDefault(t => t.DefenseDeviceId.Equals(id)); if (deleteObj == null) { return(NotFound()); } db.DefenseDevice.Remove(deleteObj); db.SaveChanges(); } return(NoContent()); }