Пример #1
0
        public static List <Teacher> GetTeachers()
        {
            var db       = new DnevnikEntities();
            var teachers = db.Teachers.Where(t => t.IsAdmin == 0).ToList();

            db.Dispose();
            return(teachers);
        }
Пример #2
0
        internal static void RemoveAllAttendance()
        {
            var db = new DnevnikEntities();

            db.Attendances.RemoveRange(db.Attendances.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Пример #3
0
        //private static

        public static int GetAllStudentsCount(int class_id)
        {
            DnevnikEntities db       = new DnevnikEntities();
            var             students = db.Students.Where(s => s.Class_id == class_id).Count();

            db.Dispose();
            return(students);
        }
Пример #4
0
        internal static void DeleteAllGrades()
        {
            var db = new DnevnikEntities();

            db.Grades.RemoveRange(db.Grades.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Пример #5
0
        public static List <Subject> GetAllSubjects()
        {
            var db       = new DnevnikEntities();
            var subjects = db.Subjects.Where(s => s.Id > 1).ToList();

            db.Dispose();
            return(subjects);
        }
Пример #6
0
        public static List <Student> GetAllStudents(int class_id)
        {
            var db       = new DnevnikEntities();
            var students = db.Students.Include("Grades").Include("Class").Include("Attendances").Where(s => s.Class_id == class_id).OrderBy(s => s.Number).ToList();

            db.Dispose();
            return(students);
        }
Пример #7
0
        public static List <Class> GetClasses()
        {
            var db      = new DnevnikEntities();
            var classes = db.Classes.Include("Teachers").Where(c => c.Id > 1)
                          .OrderBy(c => c.Number)
                          .ThenBy(c => c.Letter).ToList();

            db.Dispose();
            return(classes);
        }
Пример #8
0
        public static void DeleteAllStudents()
        {
            GradesRepository.DeleteAllGrades();
            AttendanceRepository.RemoveAllAttendance();

            var db = new DnevnikEntities();

            db.Students.RemoveRange(db.Students);
            db.SaveChanges();
            db.Dispose();
        }
Пример #9
0
        public static void ImportStudents(List <Student> students)
        {
            var db = new DnevnikEntities();

            foreach (var stud in students)
            {
                db.Students.Add(stud);
                db.Entry(stud).State = EntityState.Added;
            }
            db.SaveChanges();
            db.Dispose();
        }
Пример #10
0
        public static void AddTeacher(Teacher t)
        {
            t.Class_id = 1;
            var db = new DnevnikEntities();

            db.Teachers.Add(t);
            var entry = db.Entry(t);

            entry.State = EntityState.Added;
            db.SaveChanges();
            db.Dispose();
        }
Пример #11
0
        public static void AddNewSchedule(List <Schedule> periods)
        {
            var db = new DnevnikEntities();

            foreach (var p in periods)
            {
                db.Schedules.Add(p);
                db.Entry(p).State = EntityState.Added;
            }
            db.SaveChanges();
            db.Dispose();
        }
Пример #12
0
        public static Student GetStudent(string egn)
        {
            var dbContext = new DnevnikEntities();
            var student   = dbContext
                            .Students
                            .Include("Grades")
                            .Include("Attendances")
                            .Where(s => s.EGN == egn)
                            .FirstOrDefault();

            dbContext.Dispose();
            return(student);
        }
Пример #13
0
        public static List <Schedule> GetSchedule(int semester, int class_id)
        {
            var db       = new DnevnikEntities();
            var schedule = db.Schedules
                           .Include("Subject")
                           .Where(s => s.Class_id == class_id && s.Semester == semester)
                           .OrderBy(s => s.Day)
                           .ThenBy(s => s.Period)
                           .ToList();

            db.Dispose();
            return(schedule);
        }
Пример #14
0
        public static List <Attendance> GetAttendance(DateTime date, int class_id)
        {
            var db         = new DnevnikEntities();
            var attendance = db.Attendances
                             .Include("Student")
                             .Where(a => a.Date1 == date && a.Student.Class_id == class_id)
                             .OrderBy(a => a.Period)
                             .ThenBy(a => a.Student.Number)
                             .ToList();

            db.Dispose();
            return(attendance);
        }
Пример #15
0
        public static void AddStudent(Student student, int class_id)
        {
            Student stud = new Student()
            {
                EGN      = student.EGN,
                Number   = student.Number,
                Name     = student.Name,
                Class_id = class_id
            };

            var db = new DnevnikEntities();

            db.Students.Add(stud);
            db.Entry(stud).State = EntityState.Added;
            db.SaveChanges();
            db.Dispose();
        }
Пример #16
0
        public static void SaveStudents(List <Student> students)
        {
            var db = new DnevnikEntities();

            foreach (var s in students)
            {
                db.Students.Attach(s);
                var entry = db.Entry(s);
                entry.Property(e => e.Number).IsModified = true;
                entry.Property(e => e.Name).IsModified   = true;
                entry.Property(e => e.Note).IsModified   = true;
                entry.Property(e => e.EGN).IsModified    = true;
            }

            db.SaveChanges();
            db.Dispose();
        }
Пример #17
0
        public static List <SubjectVM> GetAllSchedule(int class_id)
        {
            var db       = new DnevnikEntities();
            var schedule = db.Schedules
                           .Include("Subject")
                           .Where(s => s.Class_id == class_id)
                           .GroupBy(x => x.Subject_id)
                           .Select(y => new SubjectVM {
                Id    = y.Key,
                Title = y.FirstOrDefault().Subject.Title
            })
                           .ToList();


            db.Dispose();

            return(schedule);
        }
Пример #18
0
        public static void DeleteStudent(int id, int class_id)
        {
            var db      = new DnevnikEntities();
            var student = db.Students.Where(s => s.Id == id && s.Class_id == class_id).FirstOrDefault();

            if (student == null)
            {
                throw new ArgumentException();
            }

            db.Grades.RemoveRange(db.Grades.Where(g => g.Student_id == id));
            db.Attendances.RemoveRange(db.Attendances.Where(a => a.Student_id == id).ToList());
            db.Students.Remove(student);
            //remove attendance records

            db.SaveChanges();
            db.Dispose();
        }
Пример #19
0
        public static List <Subject> GetSubjectsByClassAndSemester(int class_id, int semester)
        {
            var db = new DnevnikEntities();
            var sb = db.Schedules.Where(s => s.Class_id == class_id && s.Semester == semester).Select(s => s.Subject).ToList();

            List <Subject> subjects = new List <Subject>();
            List <int>     ids      = new List <int>();

            foreach (var item in sb)
            {
                if (!ids.Contains(item.Id))
                {
                    ids.Add(item.Id);
                    subjects.Add(item);
                }
            }

            db.Dispose();
            return(subjects);
        }
Пример #20
0
        public static List <Grade> GetAllGrades(int class_id, int semester)
        {
            DnevnikEntities db     = new DnevnikEntities();
            var             grades = new List <Grade>();

            if (semester == 1)
            {
                grades = db.Grades.Where(g => ((g.Grade_month >= 9 && g.Grade_month <= 12) || g.Grade_month == 1) && g.Student.Class_id == class_id).ToList();
            }
            else if (semester == 2)
            {
                grades = db.Grades.Where(g => (g.Grade_month >= 2 && g.Grade_month <= 6) && g.Student.Class_id == class_id).ToList();
            }
            else
            {
                grades = db.Grades.Where(g => g.Grade_month == semester && g.Student.Class_id == class_id).ToList();
            }

            db.Dispose();
            return(grades);
        }
Пример #21
0
        public static void AddGradesToDB(List <StudentGradesViewModel> students, int semester, int subject_id)
        {
            var db = new DnevnikEntities();

            try
            {
                //5 meseca za srok + 1 za srochna ocenka
                //ako e vtori semester + 1 za godishna ocenka
                int len = 0;
                if (semester == 1)
                {
                    len = 6;
                }
                else
                {
                    len = 7;
                }

                //za vseki uchenik vzemame ocenkite po mesec, razbivame gi i gi vkarvame v bazata
                foreach (var s in students)
                {
                    for (int i = 0; i < len; i++)
                    {
                        if (s.Grades[i] != string.Empty)
                        {
                            var grades = s.Grades[i].Split(new char[] { ',', ';' });//remove empty entries
                            foreach (var grade in grades)
                            {
                                if (grade.Trim() == string.Empty)
                                {
                                    continue;
                                }

                                int month = ConvertMonth(i, semester);

                                Grade g = new Grade
                                {
                                    Grade_month = month,
                                    Grade1      = System.Int32.Parse(grade.Trim()),
                                    Student_id  = s.Id,
                                    Subject_id  = subject_id,
                                };

                                db.Grades.Add(g);
                                db.Entry(g).State = EntityState.Added;
                            }
                        }
                    }
                }

                //iztrivame starite ocenki predi da vkarame novite
                foreach (var stud in students)
                {
                    GradesRepository.DeleteGradesBySubject(semester, stud.Id, subject_id);
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new ArgumentException();
            }
            finally
            {
                db.Dispose();
            }
        }