示例#1
0
        public int AddClassToDB <T>(T entity) where T : class
        {
            //int random = new Random().Next(1000, 10000);
            //string time = _encryption.Time().ToString("s");
            //string newTime = Regex.Replace(time, @"[^0-9]+", "");
            //classRoom.ClassRoomId = string.Format("0{0}{1}", newTime, random);
            object obj    = entity;
            int    result = -1;

            if (typeof(T) == typeof(ClassRoom))
            {
                ClassRoom classRoom = (ClassRoom)obj;
                classRoom.ClassRoomId = _encryption.SignMD5(string.Format("{0}{1}", classRoom.Grade, classRoom.ClassRoomName)).ToUpper();
                classRoom.Remark      = classRoom.Remark != null ? classRoom.Remark : "班级信息";
                obj    = classRoom;
                entity = (T)obj;
            }
            else if (typeof(T) == typeof(Students_Info))
            {
                Students_Info studentsInfo = (Students_Info)obj;
                studentsInfo.Id       = _encryption.SignMD5(string.Format("{0}{1}", studentsInfo.Name, studentsInfo.Phone)).ToUpper();
                studentsInfo.Remark   = studentsInfo.Remark != null ? studentsInfo.Remark : "学生信息";
                studentsInfo.DateTime = _encryption.Time();
                obj    = studentsInfo;
                entity = (T)obj;
            }

            else if (typeof(T) == typeof(Teacher_Info))
            {
                Teacher_Info teacherInfo = (Teacher_Info)obj;
                teacherInfo.Id       = _encryption.SignMD5(string.Format("{0}{1}", teacherInfo.Name, teacherInfo.Phone)).ToUpper();
                teacherInfo.Remark   = teacherInfo.Remark != null ? teacherInfo.Remark : "教师信息";
                teacherInfo.Password = _encryption.SignMD5(teacherInfo.Password).ToUpper();
                teacherInfo.DateTime = _encryption.Time();
                obj    = teacherInfo;
                entity = (T)obj;
            }
            _loggerHelper.WriteInfoLog(entity);
            try
            {
                _MsSqlContext.Set <T>().Add(entity);
                if (typeof(T) == typeof(Students_Info))
                {
                    Students_Info stu = (Students_Info)obj;
                    _MsSqlContext.Set <LastclassScore>().Add(new LastclassScore()
                    {
                        StudentsInfoId = stu.Id,
                        ClassInfoId    = _encryption.SignMD5(string.Format("{0}{1}", stu.Grade, stu.ClassName)).ToUpper(),
                        StudentName    = stu.Name
                    });
                }
                result = _MsSqlContext.SaveChanges();
            }
            catch (Exception e)
            {
                _loggerHelper.WriteInfoLog(e.StackTrace);
            }
            _loggerHelper.WriteInfoLog(result);
            return(result);
        }
示例#2
0
        public IActionResult CreateTeacher(Teacher_Info teacherInfo)
        {
            _loggerHelper.WriteInfoLog(teacherInfo.Name);
            object result = _create.AddClassToDB(teacherInfo);

            return(Content(result.ToString()));
        }
示例#3
0
        public bool VerifyPassword(string name, string password)
        {
            Teacher_Info result = null;

            using (MsSqlContext msSqlContext = new MsSqlContext(new UseSqlServerOptionBuilder().Option))
            {
                result = msSqlContext.TeacherInfos.Where(teach => teach.Name == name && teach.Password == password)
                         .FirstOrDefault();
            }

            if (result == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }