Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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());
        }