public IActionResult Add([FromBody] DutyGroupSchedule model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { //判断是否已存在编排 if (DutyGroupScheduleHelper.IsExist(model.StartDate, model.EndDate, model.OrganizationId)) { return(BadRequest(new ApplicationException { ErrorCode = "DataError", ErrorMessage = "当前时间已进行编排" })); } if (CompletionData(model, db)) { return(BadRequest(new ApplicationException { ErrorCode = "DataError", ErrorMessage = "编排哨位节点下的监控点数据不存在" })); } // db.DutyGroupSchedule.Add(model); db.SaveChanges(); //生成日数据 Task.Factory.StartNew(() => { DutyGroupScheduleHelper.GetAbsoultedDutyCheckLog(model); }); return(Created("", "OK")); } } catch (DbUpdateException dbEx) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public IActionResult Update([FromBody] DutyGroupSchedule model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { using (var tran = db.Database.BeginTransaction()) { DutyGroupSchedule dutyGroupSchedule = db.DutyGroupSchedule .Include(t => t.Lister) .Include(t => t.Organization) .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckMan) .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule)/*.ThenInclude(t => t.CheckDutySite).ThenInclude(t => t.Camera)*/ .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.CheckMan) .Include(t => t.Reservegroup).ThenInclude(t => t.Staff) .Include(t => t.EmergencyTeam).ThenInclude(t => t.Staff) .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(model.DutyGroupScheduleId)); if (dutyGroupSchedule == null) { return(BadRequest()); } // if (dutyGroupSchedule.StartDate <= model.StartDate && dutyGroupSchedule.EndDate >= model.EndDate) { //判断是否为进行中 Delete(dutyGroupSchedule.DutyGroupScheduleId); } //删除未进行的查勤记录 var del = db.DutyCheckLog .Where(p => p.PlanDate >= DateTime.Now && p.PlanDate <= dutyGroupSchedule.EndDate && p.StatusId != new Guid("361ADFE9-E58A-4C88-B191-B742CC212443")); if (del != null && del.Count() != 0) { db.DutyCheckLog.RemoveRange(del.ToList()); db.SaveChanges(); } //执行新增流程,重新对实体内属性GUID赋值 DutyGroupSchedule newModel = UpdateData(model); // if (CompletionData(newModel, db)) { return(BadRequest(new ApplicationException { ErrorCode = "DataError", ErrorMessage = "数据不齐" })); } // db.DutyGroupSchedule.Add(newModel); db.SaveChanges(); //生成日数据 Task.Factory.StartNew(() => { DutyGroupScheduleHelper.GetAbsoultedDutyCheckLog(newModel); }); tran.Commit(); return(new NoContentResult()); } } } catch (DbUpdateException dbEx) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }