public bool CheckLabUsable(LabApply apply) { //查询是否存在已审核的实验室/设备申请 var data = dbContext.LabApply.Where(a => a.code == apply.code && a.plan_date == apply.plan_date & a.status == 2 && a.mode == apply.mode).ToList(); { int cc = data.Where(a => a.plan_sjd1_i >= apply.plan_sjd1_i && a.plan_sjd1_i <= apply.plan_sjd2_i || a.plan_sjd2_i >= apply.plan_sjd1_i && a.plan_sjd2_i <= apply.plan_sjd2_i).ToList().Count; if (cc > 0) { return(false); } } if (apply.mode == "机房预约") { //机房预约需要校验预约时间和时间段内是否有人预约了单个座位 //如果无人预约(数量0)则返回成功 //否则返回失败 var tmp = from a in dbContext.Laboratory from b in dbContext.Device from c in dbContext.LabApply where a.code == b.laboratory_code & b.code == c.code & c.status == 2 & c.mode == "座位预约" & c.plan_date == apply.plan_date & a.code == apply.code select c; var tmpList = tmp.ToList(); int cc = tmpList.Where(a => a.plan_sjd1_i >= apply.plan_sjd1_i && a.plan_sjd1_i <= apply.plan_sjd2_i || a.plan_sjd2_i >= apply.plan_sjd1_i && a.plan_sjd2_i <= apply.plan_sjd2_i).ToList().Count; if (cc > 0) { return(false); } } if (apply.mode == "座位预约") { var device = dbContext.Device.Find(apply.code); if (device.status == 9) { return(false); } else { //座位预约需要校验预约时间和时间段内是否有人预约了整个机房 //如果无人预约(数量0)则返回成功 //否则返回失败 var tmp = from a in dbContext.Laboratory from b in dbContext.Device from c in dbContext.LabApply where a.code == b.laboratory_code & a.code == c.code & c.status == 2 & c.mode == "机房预约" & c.plan_date == apply.plan_date & a.code == apply.code select c; var tmpList = tmp.ToList(); int cc = tmpList.Where(a => a.plan_sjd1_i >= apply.plan_sjd1_i && a.plan_sjd1_i <= apply.plan_sjd2_i || a.plan_sjd2_i >= apply.plan_sjd1_i && a.plan_sjd2_i <= apply.plan_sjd2_i).ToList().Count; if (cc > 0) { return(false); } } } return(true); }
public ActionResult Save(LabApply apply) { var obj = new { code = "0000", msg = "" }; if (apply.mode == "座位预约") { var device = dbContext.Device.Find(apply.code); if (device.status == 9) { obj = new { code = "0001", msg = "设备已损坏,请更换设备重新预约" }; } } if (!CheckLabUsable(apply)) { obj = new { code = "0002", msg = "实验室/设备已被预约,请更换预约时间或时间段" }; } else { if (apply.action == "editLabApply") { //修改申请信息 dbContext.Entry(apply).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); } else { apply.user_code = Session["user_code"].AsString(); apply.user_name = Session["user_name"].AsString(); apply.user_type = Session["user_type"].AsString(); apply.status = 1; //新增申请信息 dbContext.LabApply.Add(apply); dbContext.SaveChanges(); } } //返回结果 return(Json(obj)); }