コード例 #1
0
        public ActionResult AssignSubject(SET_CLASS set_class)
        {
            decimal?USER_NO  = Session["sess_USER_NO"] as decimal?;
            decimal?LOGON_NO = Session["sess_LOGON_NO"] as decimal?;

            List <Class_Subject> subjects = set_class.Subjects;

            foreach (var subject in subjects)
            {
                decimal is_active = subject.IS_ACTIVE == true ? 1 : 0;

                db.SET_CLASS_SUBJECT_ASSIGN(set_class.CLASS_NO, subject.SUBJECT_NO, is_active, USER_NO, LOGON_NO);
            }

            subjects = (from ss in db.SET_SUBJECT
                        join cs in db.SET_CLASS_SUBJECT
                        on ss.SUBJECT_NO equals cs.SUBJECT_NO into joined
                        from j in joined.Where(a => a.CLASS_NO == set_class.CLASS_NO || a.CLASS_NO == null).DefaultIfEmpty()
                        //where (j.CLASS_NO == set_class.CLASS_NO || j.CLASS_NO == null)
                        select new Class_Subject
            {
                SUBJECT_NO = ss.SUBJECT_NO,
                SUBJECT_NAME = ss.SUBJECT_NAME,
                SUBJECT_NAME_BNG = ss.SUBJECT_NAME_BNG,
                IS_ACTIVE = j.IS_ACTIVE == 1 ? true : false
            }).OrderBy(a => a.SUBJECT_NO).ToList();

            ViewBag.Subjects = subjects;

            return(View(set_class));
        }