public OutputResult Single(string id) { var student = dbContext.Students.FirstOrDefault(x => x.StudentID == Convert.ToInt64(id)); if (student == null) { return(OutputResult.Failed("不存在此学生")); } return(OutputResult <Student> .Success(student)); }
public OutputResult Add([FromForm] Student student) { if (dbContext.Students.FirstOrDefault(x => x.StudentID == student.StudentID) != null) { return(OutputResult.Failed("已存在此学号")); } dbContext.Students.Add(student); if (dbContext.SaveChanges() < 1) { return(OutputResult.Failed("添加失败")); } return(OutputResult.Success()); }
public OutputResult Add([FromForm] Domitory domitory) { if (dbContext.Domitorys.FirstOrDefault(x => x.DomitoryID == domitory.DomitoryID) != null) { return(OutputResult.Failed("已存在此宿舍号")); } dbContext.Domitorys.Add(domitory); if (dbContext.SaveChanges() < 1) { return(OutputResult.Failed("添加失败")); } return(OutputResult.Success()); }
public OutputResult CheckOut(string id) { var student = dbContext.Students.FirstOrDefault(x => x.StudentID == Convert.ToInt64(id)); if (student == null) { return(OutputResult.Failed("不存在此学生")); } student.RoomNumber = 0; student.CheckInTime = null; dbContext.Entry(student).State = EntityState.Modified; if (dbContext.SaveChanges() < 1) { return(OutputResult.Failed("退宿失败")); } return(OutputResult.Success()); }
public OutputResult Modify([FromForm] Student student) { var oldStudent = dbContext.Students.FirstOrDefault(x => x.StudentID == student.StudentID); if (oldStudent == null) { return(OutputResult.Failed("不存在此学生")); } oldStudent.Name = student.Name; oldStudent.PhoneNumber = student.PhoneNumber; oldStudent.ClassName = student.ClassName; oldStudent.SubjectName = student.SubjectName; dbContext.Entry(oldStudent).State = EntityState.Modified; if (dbContext.SaveChanges() < 1) { return(OutputResult.Failed("添加失败")); } return(OutputResult.Success()); }