public ActionResult Create(DormExam dormexam) { if (ModelState.IsValid) { Db.DormExams.Add(dormexam); Db.SaveChanges(); return RedirectToAction("Index"); } return View(dormexam); }
public String ReceiveDormExam(int userId, DormExamRecord der) { if (der == null) { return "对象不能为空"; } var user = UserInfoDao.GetUserInfoById(userId); if (user == null) { return "用户不存在"; } var listExam = Db.DormExams.Where( u => u.SchoolYear == _schoolYear && u.Week == _week && u.DormInfo.Num == der.DormInfo && u.DormExamType.Name == "普查").ToList(); if (listExam.Count > 0 && der.DormExamType == "普查") { return "该寝室检查信息本周已被提交"; } var dormExam = new DormExam { Attitude = der.Attitude, Bed = der.Bed, DoorWindows = der.DoorWindows, DormExamType = DormExamTypeDao.GetByName(der.DormExamType), DormInfo = DormInfoDao.GetDormInfoByNum(der.DormInfo), Ground = der.Ground, Irregularity = DormIrregularityDao.GetByName(der.Irregularity), IsStop = 0, OperatorPeople = user, Point = der.Point, Grade = CalculateGrade(der.Point), Remarks = der.Remarks, Review = der.Review, Rubbish = der.Rubbish, SchoolYear = _schoolYear, Smell = der.Smell, Thing = der.Thing, Time = DateTime.Now, Toilet = der.Toilet, Week = _week, Whole = der.Whole }; Db.DormExams.Add(dormExam); Db.SaveChanges(); return "保存成功"; //验证重复 提示“该寝室检查信息本周已被提交” //判断空对象 提示“对象不能为空” //用户不存在 提示“用户不存在” //成功 提示“保存成功” // }
public ActionResult Edit(DormExam dormexam) { if (ModelState.IsValid) { Db.Entry(dormexam).State = EntityState.Modified; Db.SaveChanges(); return RedirectToAction("Index"); } return View(dormexam); }