Esempio n. 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);
        }
Esempio n. 2
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);
        }