public IActionResult Add([FromBody] VideoRoundScene sence) { if (sence == null) { return(BadRequest("VideoRoundScene object can not be null!")); } if (ExistsName(sence.VideoRoundSceneName, sence.VideoRoundSceneId)) { return(BadRequest("VideoRoundScene name has been used!")); } using (var db = new AllInOneContext.AllInOneContext()) { try { db.VideoRoundScene.Add(sence); db.SaveChanges(); return(CreatedAtAction("", sence)); } 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 Update([FromBody] VideoRoundScene sence) { if (sence == null) { return(BadRequest("VideoRoundScene object can not be null!")); } if (ExistsName(sence.VideoRoundSceneName, sence.VideoRoundSceneId)) { return(BadRequest("VideoRoundScene name has been used!")); } using (var db = new AllInOneContext.AllInOneContext()) { using (var tran = db.Database.BeginTransaction()) { try { //先删除,再更新 var dbSence = db.VideoRoundScene.Include(t => t.VideoRoundSections).ThenInclude(t => t.RoundMonitorySiteSettings) .FirstOrDefault(t => t.VideoRoundSceneId.Equals(sence.VideoRoundSceneId)); if (dbSence.VideoRoundSections != null) { dbSence.VideoRoundSections.ForEach(t => db.Set <VideoRoundMonitorySiteSetting>().RemoveRange(t.RoundMonitorySiteSettings)); db.Set <VideoRoundSection>().RemoveRange(dbSence.VideoRoundSections); } db.SaveChanges(); dbSence.ModifiedBy = sence.ModifiedBy; dbSence.Modified = DateTime.Now; dbSence.VideoRoundSceneName = sence.VideoRoundSceneName; dbSence.VideoRoundSections = sence.VideoRoundSections; db.VideoRoundScene.Update(dbSence); db.SaveChanges(); tran.Commit(); return(NoContent()); } catch (DbUpdateException dbEx) { tran.Rollback(); _logger.LogError("更新视频轮巡场景异常:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (Exception ex) { tran.Rollback(); _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()) { var groups = db.VideoRoundScene.Where(t => t.VideoRoundSceneId.Equals(id)). Include(t => t.VideoRoundSections).ThenInclude(t => t.RoundMonitorySiteSettings).ThenInclude(t => t.MonitorySite); VideoRoundScene cg = groups.FirstOrDefault(t => t.VideoRoundSceneId.Equals(id)); if (cg == null) { return(NotFound()); } return(new OkObjectResult(cg)); } }
public IActionResult Remove(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { try { VideoRoundScene deleteObj = db.VideoRoundScene.FirstOrDefault(t => t.VideoRoundSceneId.Equals(id)); if (deleteObj == null) { return(NotFound()); } db.VideoRoundScene.Remove(deleteObj); db.SaveChanges(); return(NoContent()); } catch (Exception ex) { _logger.LogError("删除轮巡场景异常:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } } }