Esempio 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));
        }
Esempio 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());
        }
Esempio n. 3
0
        public OutputResult List(string id, string domitoryId)
        {
            var temp = dbContext.Students.AsEnumerable();

            if (!string.IsNullOrEmpty(id))
            {
                temp = temp.Where(x => x.StudentID == Convert.ToInt64(id));
            }

            if (!string.IsNullOrEmpty(domitoryId))
            {
                temp = temp.Where(x => x.RoomNumber == Convert.ToInt64(domitoryId));
            }
            return(OutputResult <List <Student> > .Success(temp.ToList()));
        }
Esempio n. 4
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());
        }
Esempio n. 5
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());
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
        public OutputResult List(string id, string phone)
        {
            var temp = dbContext.Domitorys.AsEnumerable();

            if (!string.IsNullOrEmpty(id))
            {
                temp = temp.Where(x => x.DomitoryID == Convert.ToInt64(id));
            }

            if (!string.IsNullOrEmpty(phone))
            {
                temp = temp.Where(x => x.PhoneNumber.Contains(phone));
            }

            var list = temp.ToList();

            foreach (var item in temp)
            {
                item.Count = dbContext.Students.Where(x => x.RoomNumber == item.DomitoryID).Count();
            }
            return(OutputResult <List <Domitory> > .Success(list));
        }