// GET api/<controller>/5
 /// <summary>
 /// 根据班级ID获取学生
 /// </summary>
 /// <param name="classId"></param>
 /// <returns></returns>
 public Dictionary <string, string> Get(int id)
 {
     using (var db = new fz_basicEntities())
     {
         return(db.sy_student.OrderBy(o => o.Name).Where(w => w.Class == id && w.UserId != null).ToDictionary(k => k.sy_user.Account, v => v.Name));
     }
 }
Beispiel #2
0
 public static InitForm GetInitForm()
 {
     using (var db = new fz_basicEntities())
     {
         InitForm init   = new InitForm();
         sy_init  syinit = db.sy_init.FirstOrDefault();
         if (syinit != null)
         {
             init.SchoolName  = syinit.SchoolName;
             init.AuthMessage = syinit.AuthMessage;
         }
         List <dict_subject> subjectlist = db.dict_subject.Where(w => w.IsEnabled).OrderBy(o => o.Sort).ToList();
         if (subjectlist != null && subjectlist.Count > 0)
         {
             init.choEdi = new List <EdiSubGrid>();
             foreach (dict_subject subject in subjectlist)
             {
                 EdiSubGrid esg = new EdiSubGrid();
                 esg.EdiList = db.dict_edition_and_subject.Where(w => w.dict_subject.Id == subject.Id).Select(s => new Edition
                 {
                     EdiId     = s.dict_edition.Id,
                     EdiName   = s.dict_edition.Name,
                     IsEnabled = s.IsEnabled
                 }).ToList();
                 esg.SubId   = subject.Id;
                 esg.SubName = subject.Name;
                 init.choEdi.Add(esg);
             }
         }
         return(init);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        public static int Add(VModel.SyNav.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                if (db.sy_nav.Where(w => w.SId == m.SId && w.Name == m.Name.Trim()).Count() > 0)
                {
                    return(-1);//导航已存在
                }

                sy_nav dbm = new sy_nav
                {
                    PId                                 = m.PId == null?db.sy_nav.Where(w => w.Type == 3 && w.SId == m.SId).Select(s => s.Id).FirstOrDefault() : m.PId,
                                              Type      = m.PId == null ? 1 : 2,
                                              Name      = m.Name,
                                              SId       = m.SId,
                                              Url       = m.Url,
                                              PageOpen  = m.PageOpen,
                                              Icon      = m.Icon,
                                              Level     = m.PId == null ? 1 : 2,
                                              Sort      = m.Sort,
                                              IsEnabled = m.IsEnabled,
                                              IsSystem  = true
                };

                db.sy_nav.Add(dbm);
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_nav");

            return(200);
        }
Beispiel #4
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public static int Edit(VModel.SyNav.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                sy_nav dbm = db.sy_nav.Find(m.Id);
                if (dbm.Name.Trim() != m.Name.Trim() && db.sy_nav.Where(w => w.SId == m.SId && w.Name == m.Name.Trim()).Count() > 0)
                {
                    return(-1);//导航已存在
                }

                dbm.PId = m.PId == null?db.sy_nav.Where(w => w.Type == 3 && w.SId == m.SId).Select(s => s.Id).FirstOrDefault() : m.PId;

                dbm.Name = m.Name;
                //dbm.Type = m.PId == null ? 1 : 2;
                dbm.Url      = m.Url;
                dbm.PageOpen = m.PageOpen;
                //dbm.Level = m.PId == null ? 1 : 2;
                dbm.Icon      = m.Icon;
                dbm.Sort      = m.Sort;
                dbm.IsEnabled = m.IsEnabled;

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_nav");

            return(200);
        }
Beispiel #5
0
 /// <summary>
 /// 根据学科获取教师列表
 /// </summary>
 /// <param name="subjectId"></param>
 /// <returns></returns>
 public static Dictionary <int, string> GetDict(int subjectId)
 {
     using (var db = new fz_basicEntities())
     {
         return(db.sy_teacher.Where(w => w.Subject == subjectId && w.UserId != null && w.sy_user.IsEnabled == true).ToDictionary(k => k.Id, v => v.Name));
     }
 }
Beispiel #6
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);
        }
Beispiel #7
0
 /// <summary>
 /// 根据年级获取班级列表
 /// </summary>
 /// <param name="grade">年级</param>
 /// <returns></returns>
 public Dictionary <int, string> GetClassDict(int grade)
 {
     using (var db = new fz_basicEntities())
     {
         return(db.sy_class.Where(w => w.GradeId == grade).OrderBy(o => o.Sort).ToDictionary(k => k.Id, v => v.Name));
     }
 }
Beispiel #8
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int Delete(int id)
        {
            using (var db = new fz_basicEntities())
            {
                if (db.sy_student.Where(w => w.Class == id && w.sy_user.IsEnabled).Count() > 0)
                {
                    return(-1);//班级中存在学生不能删除
                }
                if (db.sy_teacher.Where(w => w.sy_teacher_and_class_and_subject.Any(a => a.ClassId == id) && w.sy_user.IsEnabled).Count() > 0)
                {
                    return(-2);//班级中存在教师不能删除
                }
                ///////////学生账号禁用置空学生年级和班级///////////
                List <sy_student> stulist = db.sy_student.Where(w => w.Class == id && w.sy_user.IsEnabled == false).ToList();
                foreach (sy_student stu in stulist)
                {
                    stu.Grade = null;
                    stu.Class = null;
                }
                ///////////老师账号被禁用删除///////////
                List <sy_teacher_and_class_and_subject> tealist = db.sy_teacher_and_class_and_subject.Where(w => w.ClassId == id && w.sy_teacher.sy_user.IsEnabled == false).ToList();
                foreach (sy_teacher_and_class_and_subject tea in tealist)
                {
                    db.sy_teacher_and_class_and_subject.Remove(db.sy_teacher_and_class_and_subject.Find(tea.TeacherId, tea.ClassId, tea.Subject));
                }
                db.sy_class.Remove(db.sy_class.Find(id));
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_class");
            return(200);
        }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public static int Edit(VModel.SyGrade.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                sy_grade dbm = db.sy_grade.Find(m.Id);

                if (dbm.Year != m.Year && db.sy_grade.Where(w => w.Year == m.Year).Count() > 0)
                {
                    return(-1);//入学年份已存在
                }
                if (dbm.SGradeId != m.Name && db.sy_grade.Where(w => w.IsGraduate == false && w.SGradeId == m.Name).Count() > 0)
                {
                    return(-2);//当前年级已存在
                }

                dbm.SGradeId = (int)m.Name;
                dbm.Name     = Common.Dict.Grade.GetVal((int)m.Name);
                dbm.Year     = (int)m.Year;
                //  dbm.Sort = m.Sort;

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_grade");

            return(200);
        }
Beispiel #11
0
        /// <summary>
        /// 获取编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static VModel.SyClass.Form GetEdit(int id)
        {
            List <VModel.SyClass.TeacherSubjectGrid> list = new List <VModel.SyClass.TeacherSubjectGrid>();
            sy_class dbm = null;

            using (var db = new fz_basicEntities())
            {
                dbm = db.sy_class.Find(id);

                Dictionary <int, string> subjectDict = DictSubjectBll.GetSelect();
                foreach (var key in subjectDict.Keys)
                {
                    list.Add(new VModel.SyClass.TeacherSubjectGrid
                    {
                        SubjectId = key,
                        TeacherId = db.sy_teacher_and_class_and_subject.Where(w => w.Subject == key && w.ClassId == id).Select(s => s.TeacherId).FirstOrDefault()
                    });
                }
            }

            return(new VModel.SyClass.Form
            {
                Id = dbm.Id,
                Name = dbm.Name,
                GradeId = dbm.GradeId,
                Sort = dbm.Sort,
                IsEnabled = dbm.IsEnabled,
                TsGrid = list
            });
        }
Beispiel #12
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        public static int Add(VModel.SyGrade.Form m)
        {
            using (var db = new fz_basicEntities())
            {
                if (db.sy_grade.Where(w => w.Year == m.Year).Count() > 0)
                {
                    return(-1);//入学年份已存在
                }
                if (db.sy_grade.Where(w => w.IsGraduate == false && w.SGradeId == m.Name).Count() > 0)
                {
                    return(-2);//当前年级已存在
                }

                db.sy_grade.Add(new sy_grade
                {
                    SGradeId = (int)m.Name,
                    Name     = Common.Dict.Grade.GetVal((int)m.Name),
                    Year     = (int)m.Year,
                    //  Sort = m.Sort,
                    IsEnabled  = true,
                    IsGraduate = false
                });

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_grade");

            return(200);
        }
Beispiel #13
0
 /// <summary>
 /// 获取教材资源(水滴)
 /// </summary>
 /// <param name="bookId">教材id</param>
 /// <param name="pages">页码(多个)</param>
 /// <returns></returns>
 public string[] GetTextbookResource(int bookId, int[] pages)
 {
     using (var db = new fz_basicEntities())
     {
         return(db.dict_textbook_resource.Where(w => w.BookId == bookId && pages.Contains(w.PageIndex)).Select(s => s.Content).ToArray());
     }
 }
Beispiel #14
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        public static List <VModel.SyRole.Grid> GetGrid(VModel.SyRole.Index m)
        {
            using (var db = new fz_basicEntities())
            {
                IQueryable <sy_role> query = db.sy_role.Where(w => w.Id != 1);
                if (m.Type != null)
                {
                    query = query.Where(w => w.Type == m.Type);
                }
                if (!string.IsNullOrWhiteSpace(m.Name))
                {
                    query = query.Where(w => w.Name.Contains(m.Name));
                }

                return(query.Select(s => new VModel.SyRole.Grid
                {
                    Id = s.Id,
                    Name = s.Name,
                    Type = s.Type,
                    UserNumber = db.sy_user_and_role.Where(w => w.sy_user.Id == w.UserId && w.sy_role.Id == s.Id && w.sy_user.IsEnabled).Count(),
                    APNumber = s.sy_nav.Count,
                    IsSystem = s.IsSystem,
                    IsEnabled = s.IsEnabled,
                    Remark = s.Remark
                }).ToList());
            }
        }
Beispiel #15
0
 /// <summary>
 /// 获取学科列表
 /// </summary>
 /// <returns></returns>
 public Dictionary <int, string> GetSubjectDict()
 {
     using (var db = new fz_basicEntities())
     {
         return(db.dict_subject.Where(w => w.IsEnabled == true).OrderBy(o => o.Sort).ToDictionary(k => k.Id, v => v.Name));
     }
 }
Beispiel #16
0
 /// <summary>
 ///  返回年级信息
 /// </summary>
 /// <param name="ClassName"></param>
 /// <returns></returns>
 public static sy_grade GetGrade(string GradeName)
 {
     using (var db = new fz_basicEntities())
     {
         sy_grade grade = db.sy_grade.Where(w => w.Name == GradeName && !w.IsGraduate && w.IsEnabled).FirstOrDefault();
         return(grade);
     }
 }
Beispiel #17
0
 /// <summary>
 /// 当前年级下班级是否存在
 /// </summary>
 /// <param name="ClassName"></param>
 /// <returns></returns>
 public static sy_class GetClass(int grade, string className)
 {
     using (var db = new fz_basicEntities())
     {
         sy_class cla = db.sy_class.Where(w => w.GradeId == grade && w.Name == className && !w.IsGraduate && w.IsEnabled).FirstOrDefault();
         return(cla);
     }
 }
Beispiel #18
0
 /// <summary>
 /// 根据版本获取年级列表
 /// </summary>
 /// <returns></returns>
 public Dictionary <int, string> GetGradeDictByEditions(string editions)
 {
     using (var db = new fz_basicEntities())
     {
         IQueryable <int> gradeIds = db.dict_textbook.Where(w => editions.Contains(w.Edition.ToString())).Select(s => s.Grade).Distinct();
         return(Common.Dict.Grade.Get().ToList().Where(w => gradeIds.Contains(w.Key)).ToDictionary(k => k.Key, v => v.Value));
     }
 }
Beispiel #19
0
 /// <summary>
 /// 获取全部用户与学科
 /// </summary>
 /// <returns></returns>
 public Dictionary <string, string> GetUserAndSubjectDict()
 {
     using (var db = new fz_basicEntities())
     {
         var list = db.sy_teacher.Join(db.dict_subject, a => a.Subject, b => b.Id, (a, b) => new { a.UserId, b.Name }).Where(w => w.UserId != null);
         return(list == null ? null : list.ToDictionary(k => k.UserId, v => v.Name));
     }
 }
Beispiel #20
0
        /// <summary>
        /// 获取教材版本
        /// </summary>
        /// <returns></returns>
        public Dictionary <int, string> GetEditionDict()
        {
            using (var db = new fz_basicEntities())
            {
                IQueryable <dict_edition> query = db.dict_edition.Where(w => w.IsEnabled == true);

                return(query.ToDictionary(k => k.Id, v => v.Name));
            }
        }
Beispiel #21
0
        /// <summary>
        /// 根据学科获取教材版本
        /// </summary>
        /// <param name="subject">学科</param>
        /// <returns></returns>
        public Dictionary <int, string> GetEditionDictBySubject(int subject)
        {
            using (var db = new fz_basicEntities())
            {
                IQueryable <int> editions = db.dict_textbook.Where(w => db.dict_edition_and_subject.Where(w1 => w1.SubjectId == subject && w1.IsEnabled).Select(s1 => s1.EditionId).Contains(w.Edition)).Select(s => s.Edition);

                return(db.dict_edition.Where(w => editions.Contains(w.Id)).ToDictionary(k => k.Id, v => v.Name));
            }
        }
Beispiel #22
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);
        }
Beispiel #23
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");
 }
Beispiel #24
0
 /// <summary>
 /// 根据教材获取目录
 /// </summary>
 /// <param name="bookId"></param>
 /// <returns></returns>
 public List <C_TextbookCatalog> GetTextbookCatalogDict(int bookId)
 {
     using (var db = new fz_basicEntities())
     {
         IQueryable <dict_textbook_catalog> query = db.dict_textbook_catalog.Where(w => w.Deleted == 0 && w.BookId == bookId);
         return(query.Select(s => new C_TextbookCatalog {
             Id = s.Id, PId = s.ParentId, Name = s.FolderName, PageStart = s.PageStart, PageEnd = s.PageEnd
         }).ToList());
     }
 }
Beispiel #25
0
        /// <summary>
        /// 启用或禁用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="enable"></param>
        public static void Enable(int id, bool enable)
        {
            using (var db = new fz_basicEntities())
            {
                sy_role dbm = db.sy_role.Find(id);
                dbm.IsEnabled = enable;
                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_role");
        }
Beispiel #26
0
 // GET api/<controller>/5
 /// <summary>
 /// 根据班级ID获取学生
 /// </summary>
 /// <param name="classId"></param>
 /// <returns></returns>
 public List <Student> Get(int id)
 {
     using (var db = new fz_basicEntities())
     {
         return(db.sy_student.Where(w => w.Class == id && w.UserId != null).Select(s => new Student {
             Account = s.sy_user.Account,
             Name = s.Name
         }).ToList());
         //return db.sy_student.OrderBy(o => o.Name).Where(w => w.Class == id && w.UserId != null).ToDictionary(k => k.sy_user.Account, v => v.Name);
     }
 }
Beispiel #27
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");
        }
Beispiel #28
0
 /// <summary>
 /// 获取用户学科
 /// </summary>
 /// <returns></returns>
 public int?GetUserSubjectId()
 {
     using (var db = new fz_basicEntities())
     {
         if (userInfo == null)
         {
             return(null);
         }
         sy_teacher teacher = db.sy_teacher.Where(w => w.UserId == userInfo.Id).FirstOrDefault();
         return(teacher == null ? null : teacher.Subject);
     }
 }
Beispiel #29
0
 /// <summary>
 /// 年是否存在
 /// </summary>
 /// <param name="ClassName"></param>
 /// <returns></returns>
 public static bool IsExist(string GradeName)
 {
     using (var db = new fz_basicEntities())
     {
         sy_grade grade = db.sy_grade.Where(w => w.Name == GradeName && !w.IsGraduate && w.IsEnabled).FirstOrDefault();
         if (grade != null)
         {
             return(true);
         }
         return(false);
     }
 }
Beispiel #30
0
        /// <summary>
        /// 保存毕业数据
        /// </summary>
        public static int SaveGraduate()
        {
            using (var db = new fz_basicEntities())
            {
                var query = db.sy_grade.Where(w => w.IsGraduate == false);

                if (query.Count() <= 0)
                {
                    return(-1);//没有适合毕业的年级
                }

                int      min_year = query.Select(s => s.Year).Min();
                sy_grade grade    = db.sy_grade.Where(w => w.Year == min_year).FirstOrDefault();

                if (grade == null || grade.Year == 0)
                {
                    return(-1);//没有适合毕业的年级
                }
                //else if (db.sy_class.Where(w => w.GradeId == grade.Id).Count() <= 0)
                //{
                //    return -2;//没有适合毕业的班级
                //}
                //else if (db.sy_student.Where(w => w.Grade == grade.Id).Count() <= 0)
                //{
                //    return -3;//没有适合毕业的学生
                //}


                grade.IsGraduate = true;

                IQueryable <sy_class> classs = db.sy_class.Where(w => w.GradeId == grade.Id);
                foreach (var m in classs)
                {
                    m.IsGraduate = true;
                }

                IQueryable <sy_student> students = db.sy_student.Where(w => w.Grade == grade.Id);
                foreach (var m in students)
                {
                    m.IsGraduate        = true;
                    m.sy_user.IsEnabled = false;
                }

                db.SaveChanges();
            }

            Common.Caches.RemoveCache("sy_grade");
            Common.Caches.RemoveCache("sy_class");
            Common.Caches.RemoveCache("sy_student");

            return(200);
        }