Пример #1
0
        public bool Insert(Exam exam, int[] selectedID)
        {
            var _classDao = new ClassDAO();

            exam.Classes = new List <Class>();

            foreach (var i in selectedID)
            {
                var _class = new Class();
                if (i == 0)
                {
                    //Chọn tất cả lớp
                    int[] allClass = _classDao.GetAllClassID();
                    for (int k = 0; k < allClass.Length; k++)
                    {
                        //var c = _classDao.GetClassById(k);
                        var _id = allClass[k];
                        exam.Classes.Add(db.Classes.Single(c => c.Id == _id));
                    }
                    break;
                }
                else
                {
                    _class = _classDao.GetClassById(i);

                    exam.Classes.Add(db.Classes.Single(c => c.Id == i));
                    //exam.Classes.Add(_class);
                }
            }
            db.Exams.Add(exam);
            db.SaveChanges();
            return(true);
        }
Пример #2
0
        public IEnumerable <Exam> GetAllExamUserPageList(int?id, string searchString, int page = 1, int pageSize = 10)
        {
            var user   = new UserDAO().GetUserById(id);
            var _class = new ClassDAO().GetClassById(user.ClassID);
            IQueryable <Exam> model     = db.Exams;
            List <Exam>       queryable = new List <Exam>();

            if (!String.IsNullOrEmpty(searchString))
            {
                model = model.Where(x => x.Titile.Contains(searchString) ||
                                    x.NoteEncode.Contains(searchString) ||
                                    x.Note.Contains(searchString));
            }

            if (_class.Exams != null)
            {
                foreach (var item in _class.Exams.ToList())
                {
                    var e = model.Where(x => x.Id == item.Id).FirstOrDefault();
                    if (e != null)
                    {
                        queryable.Add(e);
                    }
                }
            }
            queryable.AsQueryable();
            return(queryable.OrderByDescending(x => x.CreatedDate).ThenBy(x => x.Status).ToPagedList(page, pageSize));
        }
Пример #3
0
        public List <Subject> GetSubjectByClassID(int?id)
        {
            var _class = new ClassDAO().GetClassById(id);

            if (_class != null)
            {
                return(db.Subjects.Where(x => x.GradeID == _class.GradeID).ToList());
            }
            return(null);
        }
Пример #4
0
        public bool Update(Exam exam, int[] selectedID)
        {
            var _exam     = db.Exams.Find(exam.Id);
            var _classDao = new ClassDAO();

            foreach (var i in _exam.Classes.ToList())
            {
                _exam.Classes.Remove(i);
            }
            db.SaveChanges();
            _exam.Classes = new List <Class>();

            foreach (var i in selectedID)
            {
                var _class = new Class();
                if (i == 0) //Chọn tất cả lớp
                {
                    int[] allClass = _classDao.GetAllClassID();
                    for (int k = 0; k < allClass.Length; k++)
                    {
                        var _id = allClass[k];
                        _exam.Classes.Add(db.Classes.Single(c => c.Id == _id));
                    }
                    break;
                }
                else
                {
                    _class = _classDao.GetClassById(i);
                    _exam.Classes.Add(db.Classes.Single(c => c.Id == i));
                }
            }
            //db.Entry(_exam).CurrentValues.SetValues(exam);
            _exam.Titile        = exam.Titile;
            _exam.Note          = exam.Note;
            _exam.NoteEncode    = exam.NoteEncode;
            _exam.SubjectID     = exam.SubjectID;
            _exam.NumberOfTurns = exam.NumberOfTurns;
            _exam.FromDate      = exam.FromDate;
            _exam.ToDate        = exam.ToDate;
            _exam.StartTime     = exam.StartTime;
            _exam.EndTime       = exam.EndTime;
            _exam.ModifiedBy    = exam.ModifiedBy;
            _exam.ModifiedDate  = exam.ModifiedDate;
            _exam.Status        = exam.Status;

            db.SaveChanges();
            return(true);
        }