Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }