public IActionResult Update([FromBody] PresetSite presetSite) { if (presetSite == null) { return(BadRequest("PresetSite object can not be null!")); } if (ExistsName(presetSite.PresetSizeName, presetSite.CameraId, presetSite.PresetSiteId)) { return(BadRequest("PresetSite name has been used!")); } using (var db = new AllInOneContext.AllInOneContext()) { try { db.PresetSite.Update(presetSite); 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 Remove(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { PresetSite deleteObj = db.PresetSite.FirstOrDefault(t => t.PresetSiteId.Equals(id)); if (deleteObj == null) { return(NotFound()); } db.PresetSite.Remove(deleteObj); db.SaveChanges(); return(NoContent()); } }