public IActionResult CreateSubject(Subject subject,string teacher) { var student = DB.Students .Where(x => x.UserId == User.Current.Id) .SingleOrDefault(); var sub = DB.Subjects .Include(x=>x.Student) .Where(x => x.Title == subject.Title&&x.Student.IsGraduate==IsGraduate.否&&x.Student.MajorId==student.MajorId) .SingleOrDefault(); if (student == null) { return Content("error"); } else { if (sub != null) { return Content("重复添加"); } else { if (student.State == State.锁定) { return Content("锁定"); } else { var tea = DB.Teachers .Where(x => x.Name == teacher) .SingleOrDefault(); subject.Draw = Draw.待审核; subject.StudentId = student.Id; subject.TeacherId = tea.Id; subject.PostTime = DateTime.Now; DB.Subjects.Add(subject); DB.SaveChanges(); var log = new Log { Time = DateTime.Now, Roles = Roles.学生, Operation = Operation.添加毕业设计选题, UserId = User.Current.Id, Number = subject.Id, }; DB.Logs.Add(log); DB.SaveChanges(); return Content("success"); } } } }
public IActionResult FixedStudent(string teachername,string studentname,string subjecttitle) { var teacher = DB.Teachers .Where(x => x.Name == teachername && x.MajorId == DB.Teachers .Where(y => y.UserId == User.Current.Id) .SingleOrDefault() .MajorId) .SingleOrDefault(); var student = DB.Students .Where(x => x.Name == studentname && x.MajorId == DB.Teachers .Where(y => y.UserId == User.Current.Id) .SingleOrDefault() .MajorId&&x.IsGraduate==IsGraduate.否) .SingleOrDefault(); var sub = DB.Subjects .Include(x=>x.Student) .Where(x => x.Student.MajorId == DB.Teachers .Where(y => y.UserId == User.Current.Id) .SingleOrDefault() .MajorId&&x.Student.Name==studentname&&x.Student.IsGraduate==IsGraduate.否) .ToList(); foreach(var x in sub) { //DB.Subjects.Remove(x); x.Draw = Draw.未通过; } var subject = new Subject { TeacherId=teacher.Id, StudentId=student.Id, DrawTime=DateTime.Now, PostTime=DateTime.Now, Draw=Draw.通过, Title=subjecttitle, }; DB.Subjects.Add(subject); student.State = State.锁定; var log = new Log { Operation = Operation.添加学生, Roles = Roles.系主任, Number = student.Id, Time = DateTime.Now, UserId = User.Current.Id, }; DB.Logs.Add(log); var info = DB.Informations.Add(new Information { SNumber = student.Id, TNumber = DB.Teachers.Where(x => x.UserId == User.Current.Id).SingleOrDefault().Id, CreateTime = DateTime.Now, IsRead = false, Content = "系主任 " + DB.Teachers.Where(x => x.UserId == User.Current.Id).SingleOrDefault().Name + " 已经将你的题目改为《" + subjecttitle + "》,指导老师为" + teachername, }); DB.SaveChanges(); return RedirectToAction("Subject", "Admin"); }