Пример #1
0
        public static bool Update(int cspId, int subjectId, int schoolYearId, string matrials, List <int> teacherIds, int LoggeduserId)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            CSP _item = _context.CSPs.FirstOrDefault(a => a.Id == cspId);

            _item.SubjectId    = subjectId;
            _item.SchoolYearId = schoolYearId;
            _item.Materials    = matrials;
            List <TeacherCSP> allteachers = _item.TeacherCSPs.ToList();

            for (int i = 0; i < allteachers.Count; i++)
            {
                _context.TeacherCSPs.Remove(allteachers[i]);
            }
            foreach (int item in teacherIds)
            {
                TeacherCSP _juTable = new TeacherCSP();
                _juTable.TeacherId       = item;
                _juTable.CreationDate    = DateTime.Now;
                _juTable.CreatedByUserId = LoggeduserId;
                _item.TeacherCSPs.Add(_juTable);
            }
            _context.SaveChanges();
            return(true);
        }
Пример #2
0
        public static bool AddNew(int studentId, int subjectId, int schoolYearId, string matrials, List <int> teacherIds, int LoggeduserId)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            CSP _item = new Sinaicsp_API.CSP();

            _item.SubjectId    = subjectId;
            _item.StudentId    = studentId;
            _item.SchoolYearId = schoolYearId;
            _item.Materials    = matrials;
            foreach (int item in teacherIds)
            {
                TeacherCSP _juTable = new TeacherCSP();
                _juTable.TeacherId       = item;
                _juTable.CreationDate    = DateTime.Now;
                _juTable.CreatedByUserId = LoggeduserId;
                _item.TeacherCSPs.Add(_juTable);
            }
            _item.Comments        = string.Empty;
            _item.FebruaryNotes   = string.Empty;
            _item.JuneNotes       = string.Empty;
            _item.CreationDate    = DateTime.Now;
            _item.CreatedByUserId = LoggeduserId;
            _context.CSPs.Add(_item);
            _context.SaveChanges();
            return(true);
        }