Esempio n. 1
0
        // GET api/<controller>/5
        /// <summary>
        /// 根据帐号获取用户信息
        /// </summary>
        /// <param name="account">帐号</param>
        /// <returns></returns>
        public C_UserInfo Get(string id)
        {
            C_UserInfo userinfo = null;

            using (var db = new fz_basicEntities())
            {
                sy_user m   = db.sy_user.Where(w => w.Account == id.Trim()).FirstOrDefault();
                int     tid = db.sy_teacher.Where(w => w.UserId == m.Id).Select(s => s.Id).FirstOrDefault();
                if (m != null)
                {
                    userinfo           = new C_UserInfo();
                    userinfo.Id        = m.Id;
                    userinfo.Type      = m.Type;
                    userinfo.Account   = m.Account;
                    userinfo.Name      = m.Name;
                    userinfo.Subject   = 3;
                    userinfo.userClass = db.sy_class.Where(w => db.sy_teacher_and_class_and_subject.Any(a => a.TeacherId == tid && a.ClassId == w.Id)).Select(s => new C_UserClass
                    {
                        ClassId   = s.Id,
                        ClassName = s.Name,
                        GradeId   = s.sy_grade.Id,
                        GradeName = s.sy_grade.Name
                    }).ToArray();
                }
            }

            return(userinfo);
        }
Esempio n. 2
0
        // GET api/<controller>/5
        public int Get(string account, string password)
        {
            int rv = 1;

            using (var db = new fz_basicEntities())
            {
                sy_user user = db.sy_user.Where(w => w.Account == account.Trim()).FirstOrDefault();

                if (user == null)
                {
                    rv = -1;//账号不存在
                }
                else if (user.Password != Common.Function.MD5Encrypt(password.Trim()))
                {
                    rv = -2;//密码错误
                }
                else if (user.IsEnabled == false)
                {
                    rv = -3;//账号已停用
                }
                else
                {
                    db.SaveChanges();
                }
            }

            return(rv);
        }
Esempio n. 3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        public static int AddStudent(VModel.SyUserStudent.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                m.Account = m.Account.Trim();
                if (db.sy_user.Where(w => w.Account == m.Account).Count() > 0)
                {
                    return(-1);//帐号已存在
                }

                sy_user dbm = new sy_user
                {
                    Id          = Guid.NewGuid().ToString(),
                    Account     = m.Account,
                    Name        = m.Name.Trim(),
                    ExpiresTime = m.ExpiresTime,
                    IsEnabled   = m.IsEnabled,
                    Password    = Common.Function.MD5Encrypt("123456"),
                    IsSystem    = false,
                    IsExpires   = false,
                    Type        = 26,
                    CreateTime  = DateTime.Now
                };

                if (m.RoleIds != null)
                {
                    foreach (int item in m.RoleIds)
                    {
                        dbm.sy_user_and_role.Add(new sy_user_and_role
                        {
                            UserId = dbm.Id,
                            RoleId = item,
                            Time   = DateTime.Now
                        });
                    }
                }

                sy_student dbm2 = new sy_student
                {
                    UserId = dbm.Id,
                    Name   = dbm.Name,
                    Sex    = m.Sex,
                    Grade  = m.Grade,
                    Class  = m.Class
                };

                db.sy_user.Add(dbm);
                db.sy_student.Add(dbm2);
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_student");

            return(200);
        }
Esempio n. 4
0
 /// <summary>
 /// 重置密码
 /// </summary>
 /// <param name="id"></param>
 public static void ResetPwd(string id)
 {
     using (var db = new fz_basicEntities())
     {
         sy_user user = db.sy_user.Find(id);
         user.Password = Common.Function.MD5Encrypt("123456");
         db.SaveChanges();
     }
     Common.Caches.RemoveCache("sy_user");
 }
Esempio n. 5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void DeleteManager(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user m = db.sy_user.Find(id);
                m.sy_user_and_role.Clear();
                db.sy_user.Remove(m);
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
        }
Esempio n. 6
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void DeleteStudent(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user m = db.sy_user.Find(id);
                m.sy_user_and_role.Clear();
                db.sy_user.Remove(m);
                db.sy_student.Remove(db.sy_student.FirstOrDefault(w => w.UserId == id));
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_student");
        }
Esempio n. 7
0
        /// <summary>
        /// 导入学生用户
        /// </summary>
        public static int ImportStudent(List <VModel.SyUserStudent.ImportData> list)
        {
            using (var db = new fz_basicEntities())
            {
                foreach (var m in list)
                {
                    sy_user user = db.sy_user.Where(w => w.Account == m.Account).FirstOrDefault();
                    if (user == null)
                    {
                        sy_user dbm = new sy_user
                        {
                            Id         = Guid.NewGuid().ToString(),
                            Account    = m.Account,
                            Name       = m.Name,
                            IsEnabled  = true,
                            Password   = Common.Function.MD5Encrypt("123456"),
                            IsSystem   = false,
                            IsExpires  = false,
                            Type       = 26,
                            CreateTime = DateTime.Now
                        };

                        dbm.sy_user_and_role.Add(new sy_user_and_role
                        {
                            UserId = dbm.Id,
                            RoleId = 4,
                            Time   = DateTime.Now
                        });
                        int        grade = Bll.SyGradeBll.GetGrade(m.Grade).Id;
                        int        cla   = Bll.SyClassBll.GetClass(grade, m.Class).Id;
                        sy_student dbm2  = new sy_student
                        {
                            UserId = dbm.Id,
                            Name   = dbm.Name,
                            Sex    = m.Sex,
                            Grade  = grade,
                            Class  = cla
                        };
                        db.sy_user.Add(dbm);
                        db.sy_student.Add(dbm2);
                        db.SaveChanges();
                    }
                }
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_student");

            return(200);
        }
Esempio n. 8
0
        /// <summary>
        /// 导入教职工用户
        /// </summary>
        public static int ImportTeacher(List <VModel.SyUserTeacher.ImportData> list)
        {
            using (var db = new fz_basicEntities())
            {
                foreach (var m in list)
                {
                    sy_user user = db.sy_user.Where(w => w.Account == m.Account).FirstOrDefault();
                    if (user == null)
                    {
                        sy_user dbm = new sy_user
                        {
                            Id         = Guid.NewGuid().ToString(),
                            Account    = m.Account,
                            Name       = m.Name,
                            IsEnabled  = true,
                            Password   = Common.Function.MD5Encrypt("123456"),
                            IsSystem   = false,
                            IsExpires  = false,
                            Type       = 12,
                            CreateTime = DateTime.Now
                        };

                        dbm.sy_user_and_role.Add(new sy_user_and_role
                        {
                            UserId = dbm.Id,
                            RoleId = 3,
                            Time   = DateTime.Now
                        });

                        sy_teacher dbm2 = new sy_teacher
                        {
                            UserId  = dbm.Id,
                            Name    = dbm.Name,
                            Subject = db.dict_subject.Where(w => w.Name == m.SubjectName).Select(s => s.Id).FirstOrDefault()
                        };

                        db.sy_user.Add(dbm);
                        db.sy_teacher.Add(dbm2);
                        db.SaveChanges();
                    }
                }
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_teacher");

            return(200);
        }
Esempio n. 9
0
        /// <summary>
        /// 启用或禁用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="enable"></param>
        public static void Enable(string id, bool enable)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user dbm = db.sy_user.Find(id);
                dbm.IsEnabled = enable;
                if (enable == true)
                {
                    dbm.ExpiresTime = null;
                    dbm.IsExpires   = false;
                }
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
        }
Esempio n. 10
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public static int EditStudent(VModel.SyUserStudent.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                m.Account = m.Account.Trim();
                sy_user dbm = db.sy_user.Find(m.Id);
                if (dbm.Account != m.Account && db.sy_user.Where(w => w.Account == m.Account).Count() > 0)
                {
                    return(-1);//帐号已存在
                }

                dbm.Account     = m.Account;
                dbm.Name        = m.Name.Trim();
                dbm.ExpiresTime = m.ExpiresTime;
                dbm.IsEnabled   = m.IsEnabled;
                dbm.sy_user_and_role.Clear();

                if (m.RoleIds != null)
                {
                    foreach (int item in m.RoleIds)
                    {
                        dbm.sy_user_and_role.Add(new sy_user_and_role
                        {
                            UserId = dbm.Id,
                            RoleId = item,
                            Time   = DateTime.Now
                        });
                    }
                }

                sy_student dbm1 = db.sy_student.FirstOrDefault(w => w.UserId == m.Id);
                if (dbm1 != null)
                {
                    dbm1.Name  = m.Name;
                    dbm1.Sex   = m.Sex;
                    dbm1.Grade = m.Grade;
                    dbm1.Class = m.Class;
                }

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_student");

            return(200);
        }
Esempio n. 11
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public static int EditTeacher(VModel.SyUserTeacher.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                m.Account = m.Account.Trim();
                sy_user dbm = db.sy_user.Find(m.Id);
                if (dbm.Account != m.Account && db.sy_user.Where(w => w.Account == m.Account).Count() > 0)
                {
                    return(-1);//帐号已存在
                }

                dbm.Account     = m.Account;
                dbm.Name        = m.Name.Trim();
                dbm.ExpiresTime = m.ExpiresTime;
                dbm.IsEnabled   = m.IsEnabled;
                dbm.sy_user_and_role.Clear();

                if (m.RoleIds != null)
                {
                    foreach (int item in m.RoleIds)
                    {
                        dbm.sy_user_and_role.Add(new sy_user_and_role
                        {
                            UserId = dbm.Id,
                            RoleId = item,
                            Time   = DateTime.Now
                        });
                    }
                }

                sy_teacher dbm1 = db.sy_teacher.FirstOrDefault(w => w.UserId == m.Id);
                if (dbm1 != null)
                {
                    dbm1.Name    = m.Name;
                    dbm1.Subject = m.Subject;
                }

                db.SaveChanges();
            }
            Task excetion = MyResourceBll.UpdateResourceCreaterName(m.Id, m.Name);

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_teacher");

            return(200);
        }
Esempio n. 12
0
        /// <summary>
        /// 获取编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static VModel.SyUserManager.Form GetEditManager(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user dbm = db.sy_user.Find(id);

                return(new VModel.SyUserManager.Form
                {
                    Id = dbm.Id,
                    Account = dbm.Account,
                    Name = dbm.Name,
                    ExpiresTime = dbm.ExpiresTime,
                    IsEnabled = dbm.IsEnabled,
                    RoleIds = dbm.sy_user_and_role.Select(s => s.sy_role.Id).ToList()
                });
            }
        }
Esempio n. 13
0
        public JsonData Get(string account, string password)
        {
            int            rv  = 1;
            List <Student> stu = null;

            using (var db = new fz_basicEntities())
            {
                sy_user user = db.sy_user.Where(w => w.Account == account.Trim()).FirstOrDefault();

                if (user == null)
                {
                    return(new JsonData {
                        msg = "账号不存在"
                    });
                }
                else if (user.Password != Common.Function.MD5Encrypt(password.Trim()))
                {
                    return(new JsonData {
                        msg = "密码不正确"
                    });
                }
                else if (user.IsEnabled == false)
                {
                    return(new JsonData {
                        msg = "账号已停用"
                    });
                }
                string FilePath = string.Format("{0}{1}/{2}.{3}", System.Configuration.ConfigurationManager.AppSettings["FileServer"], "KingsunFiles/AvatarFile", user.Id, "jpg");

                sy_user m = db.sy_user.Where(w => w.Account == account.Trim()).FirstOrDefault();
                stu = db.sy_student.Where(w => w.UserId == m.Id).Select(s => new Student
                {
                    Id         = s.Id,
                    IsGraduate = s.IsGraduate,
                    Name       = s.Name,
                    Sex        = s.Sex,
                    Type       = m.Type,
                    UserID     = m.Id,
                    year       = s.Year,
                    Avatar     = FilePath
                }).ToList();
                return(new JsonData {
                    data = stu
                });
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 获取编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static VModel.SyUserTeacher.Form GetEditTeacher(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user dbm = db.sy_user.Find(id);

                return(new VModel.SyUserTeacher.Form
                {
                    Id = dbm.Id,
                    Account = dbm.Account,
                    Name = dbm.Name,
                    Subject = dbm.sy_teacher.Select(s2 => s2.Subject).FirstOrDefault(),
                    ExpiresTime = dbm.ExpiresTime,
                    IsEnabled = dbm.IsEnabled,
                    RoleIds = dbm.sy_user_and_role.Select(s => s.sy_role.Id).ToList()
                });
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static int Check(string account, string password)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user user = db.sy_user.Where(w => w.Account == account.Trim()).FirstOrDefault();

                if (user == null)
                {
                    return(-1);//账号不存在
                }
                else if (user.Password.Trim() != Common.Function.MD5Encrypt(password.Trim()))
                {
                    return(-2);//密码错误
                }
                else if (user.IsEnabled == false)
                {
                    return(-3);//账号已停用
                }
                else if (user.ExpiresTime != null && ((DateTime)user.ExpiresTime).Date < DateTime.Now.Date)
                {
                    return(-3);//账号已停用
                }
                else if (user.Type == 26)
                {
                    return(-4);//学生账号功能尚未开通
                }
            }

            using (var db = new fz_basicEntities())
            {
                //停用数据库中所有过期的账户
                DateTime DateNow = DateTime.Now.Date;
                var      query   = db.sy_user.Where(w => w.ExpiresTime != null && DbFunctions.TruncateTime(w.ExpiresTime) <= DbFunctions.TruncateTime(DateNow)).ToList();
                foreach (var q in query)
                {
                    q.IsExpires = true;
                    q.IsEnabled = false;
                }
                db.SaveChanges();
            }

            return(1);
        }
Esempio n. 16
0
 /// <summary>
 /// 判断用户名和姓名是否存在
 /// </summary>
 /// <param name="Account"></param>
 /// <returns></returns>
 public static bool IsExist(string Account, string Name)
 {
     using (var db = new fz_basicEntities())
     {
         sy_user user = new sy_user();
         if (Name == null)
         {
             user = db.sy_user.Where(w => w.Account == Account).FirstOrDefault();
         }
         if (Account == null)
         {
             user = db.sy_user.Where(w => w.Name == Name).FirstOrDefault();
         }
         if (user != null)
         {
             return(true);
         }
         return(false);
     }
 }
Esempio n. 17
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void DeleteTeacher(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user m = db.sy_user.Find(id);
                m.sy_user_and_role.Clear();
                db.sy_user.Remove(m);

                sy_teacher m1 = db.sy_teacher.FirstOrDefault(w => w.UserId == id);
                if (m1 != null)
                {
                    m1.UserId = null;
                }

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_user");
            Common.Caches.RemoveCache("sy_teacher");
        }
Esempio n. 18
0
        /// <summary>
        /// 获取编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static VModel.SyUserStudent.Form GetEditStudent(string id)
        {
            using (var db = new fz_basicEntities())
            {
                sy_user dbm = db.sy_user.Find(id);

                return(new VModel.SyUserStudent.Form
                {
                    Id = dbm.Id,
                    Account = dbm.Account,
                    Name = dbm.Name,
                    Sex = dbm.sy_student.Select(s2 => s2.Sex).FirstOrDefault(),
                    Grade = dbm.sy_student.Select(s2 => s2.Grade).FirstOrDefault(),
                    Class = dbm.sy_student.Select(s2 => s2.Class).FirstOrDefault(),
                    ExpiresTime = dbm.ExpiresTime,
                    IsEnabled = dbm.IsEnabled,
                    RoleIds = dbm.sy_user_and_role.Select(s => s.sy_role.Id).ToList()
                });
            }
        }
Esempio n. 19
0
 public int Post(string id, [FromBody] Person model)
 {
     if (model == null)
     {
         return(0);   // 提交信息有误
     }
     else
     {
         if (model.OldPasswd == null)
         {
             return(0);   // 提交信息有误
         }
         if (model.NewPasswd == null)
         {
             return(0);   // 提交信息有误
         }
         using (var db = new fz_basicEntities())
         {
             sy_user user = db.sy_user.Find(id);
             if (user == null)
             {
                 return(-1); // 账号不存在
             }
             if (Common.Function.MD5Encrypt(model.OldPasswd) != user.Password)
             {
                 return(100); // 原始密码错误
             }
             user.Password = Common.Function.MD5Encrypt(model.NewPasswd);
             if (db.SaveChanges() == 0)
             {
                 return(400); // 修改失败
             }
             else
             {
                 return(200); // 密码修改成功
             }
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// 根据帐号获取用户信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static VModel.SyPassport.UserInfo GetUserInfo(string account)
        {
            VModel.SyPassport.UserInfo userinfo = null;
            using (var db = new fz_basicEntities())
            {
                sy_user user = db.sy_user.Where(w => w.Account == account.Trim()).FirstOrDefault();

                if (user != null)
                {
                    userinfo         = new VModel.SyPassport.UserInfo();
                    userinfo.Id      = user.Id;
                    userinfo.Account = user.Account;
                    userinfo.Name    = user.Name;
                    userinfo.Type    = user.Type;
                    userinfo.Navs    = db.sy_nav.Where(w => w.sy_role.Where(w1 => w1.sy_user_and_role.Where(w2 => w2.UserId == user.Id && w2.sy_role.IsEnabled == true).Any()).Any()).Select(s => s.Id).ToArray();

                    var sids  = db.sy_nav.Where(w => userinfo.Navs.Contains(w.Id)).Select(s => s.SId).Distinct();
                    var spids = db.sy_system.Where(w => sids.Contains(w.Id)).Select(s => s.PId);
                    userinfo.SysNavs = db.sy_system.Where(w => sids.Contains(w.Id) || spids.Contains(w.Id)).Select(s => s.Id).ToArray();
                }
            }

            return(userinfo);
        }