示例#1
0
 public static Schedule deleteLesson(int scheduleId)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         Schedule schedule = new Schedule();
         foreach (var item in db.Schedules)
         {
             if (item.ScheduleId == scheduleId)
             {
                 schedule = item;
                 db.Schedules.Remove(item);
                 if (schedule != null)
                 {
                     break;
                 }
             }
         }
         try
         {
             db.SaveChanges();
             return(schedule);
         }
         catch (Exception e)
         {
             return(null);
         }
     }
 }
示例#2
0
        public static void updateStudent(StudentDTO.UserAndStudentDTO userAndStudentDTO, int id)
        {
            using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
            {
                foreach (var user in db.Users)
                {
                    if (user.userId == id)
                    {
                        user.firstName = userAndStudentDTO.firstName;
                        user.city      = userAndStudentDTO.city;
                        user.lastName  = userAndStudentDTO.lastName;
                        user.street    = userAndStudentDTO.street;
                        user.numhouse  = userAndStudentDTO.numhouse;
                        user.phone     = userAndStudentDTO.phone;
                        user.password  = userAndStudentDTO.password;
                        user.email     = userAndStudentDTO.email;
                        user.tz        = userAndStudentDTO.tz;
                    }
                    ;
                }
                foreach (var student in db.Students)
                {
                    if (student.StudentId == id)
                    {
                        student.IdGrade = userAndStudentDTO.IdGrade;
                        student.Level   = userAndStudentDTO.Level;
                    }
                }

                db.SaveChanges();
            }
        }
示例#3
0
 public static List <Schedule> GetLessons()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Schedules.ToList());
     }
 }
示例#4
0
        public static bool UpdateSubject(SubjectToTeacherDTO subject)
        {
            bool flag = false;

            using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
            {
                foreach (var i in db.SubjectToTeachers)
                {
                    if (i.TeacherId == subject.TeacherId && i.Subject.Contains(subject.SubjectName))
                    {
                        i.GradesRange    = subject.GradesRange;
                        i.PriceForLesson = subject.PriceForLesson;
                        flag             = true;
                        break;
                    }
                }
                db.SaveChanges();
                if (flag == true)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#5
0
 public static List <Lesson> GetNotes(int id)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Lessons.ToList());
     }
 }
示例#6
0
 public static List <Student> GetStudents()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Students.ToList());
     }
 }
示例#7
0
        public static void updateTeacher(TeacherDTO.UserAndTeacherDTO userAndTeacherDTO, int id)
        {
            using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
            {
                foreach (var user in db.Users)
                {
                    if (user.userId == id)
                    {
                        user.firstName = userAndTeacherDTO.firstName;
                        user.city      = userAndTeacherDTO.city;
                        user.lastName  = userAndTeacherDTO.lastName;
                        user.street    = userAndTeacherDTO.street;
                        user.numhouse  = userAndTeacherDTO.numhouse;
                        user.phone     = userAndTeacherDTO.phone;
                        user.password  = userAndTeacherDTO.password;
                        user.email     = userAndTeacherDTO.email;
                        user.tz        = userAndTeacherDTO.tz;
                        break;
                    }
                    ;
                }
                foreach (var teacher in db.Teachers)
                {
                    if (teacher.TeacherId == id)
                    {
                        teacher.Qualifications = userAndTeacherDTO.Qualifications;
                        break;
                    }
                }

                db.SaveChanges();
            }
        }
示例#8
0
 public static List <Hour> getHours()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Hours.ToList());
     }
 }
示例#9
0
 public static List <Recommendation> GetRecrecommendationById()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Recommendations.ToList());
     }
 }
示例#10
0
 public static List <Teacher> GetTeachers()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Teachers.ToList());
     }
 }
示例#11
0
 public static void addTeacher(Teacher teacher, User user)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.Teachers.Add(teacher);
         db.Users.Add(user);
         try
         {
             db.SaveChanges();
             //_context.SaveChanges();
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
         {
             Exception raise = dbEx;
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     string message = string.Format("{0}:{1}",
                                                    validationErrors.Entry.Entity.ToString(),
                                                    validationError.ErrorMessage);
                     // raise a new exception nesting
                     // the current instance as InnerException
                     raise = new InvalidOperationException(message, raise);
                 }
             }
             throw raise;
         }
         db.SaveChanges();
     }
 }
示例#12
0
 public static List <Vacation> getVacation()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         return(db.Vacations.ToList());
     }
 }
示例#13
0
        public static void AddStudent(Student student, User user)
        {
            using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
            {
                db.Users.Add(user);
                db.Students.Add(new Student()
                {
                    IdGrade = student.IdGrade, Level = student.Level, StudentId = user.userId
                });

                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
                db.SaveChanges();
            }
        }
示例#14
0
 public static List <SubjectToTeacher> GetSubjectToTeachers()
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         var q = db.SubjectToTeachers.ToList();
         return(q);
     }
 }
示例#15
0
 public static void AddTeacher(Teacher teacher)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.Teachers.Add(teacher);
         db.SaveChanges();
     }
 }
示例#16
0
 public static void AddLesson(Hour hour)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.Hours.Add(hour);
         db.SaveChanges();
     }
 }
示例#17
0
 public static void AddLesson(Schedule schedule)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.Schedules.Add(schedule);
         db.SaveChanges();
     }
 }
示例#18
0
 public static void HoursForTeacherAdd(HoursForTeacher hoursForTeacher)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.HoursForTeachers.Add(hoursForTeacher);
         db.SaveChanges();
     }
 }
示例#19
0
 public static void AddUser(User User)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         db.Users.Add(User);
         db.SaveChanges();
     }
 }
示例#20
0
 public static void AddRecommendation(string value, int id)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         Recommendation recommendation = new Recommendation()
         {
             TeacherId = id,
             RecommendationContents = value,
         };
         db.Recommendations.Add(recommendation);
         db.SaveChanges();
     }
 }
示例#21
0
 public static void DeleteHoursAndDaysForTeacher(int id)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         foreach (var item in db.HoursForTeachers)
         {
             if (item.HoursForTeacherId == id)
             {
                 db.HoursForTeachers.Remove(item);
                 db.SaveChanges();
             }
         }
     }
 }
示例#22
0
        public static void AddNote(int id, string value, DateTime date)
        {
            using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
            {
                db.Lessons.Add(new Lesson()
                {
                    ScheduleId     = id,
                    Date           = date,
                    LessonDescribe = value
                });

                db.SaveChanges();
            }
        }
示例#23
0
 public static bool AddSubjectToTeacher(SubjectToTeacher subjectToTeacher)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         int index = db.SubjectToTeachers.ToList().FindIndex(item => item.TeacherId == subjectToTeacher.TeacherId &&
                                                             item.Subject.Contains(subjectToTeacher.Subject) && item.GradesRange.Contains(subjectToTeacher.GradesRange));
         if (index >= 0)
         {
             return(true);
         }
         db.SubjectToTeachers.Add(subjectToTeacher);
         db.SaveChanges();
         return(false);
     }
 }
示例#24
0
 public static void DeleteStudent(int id)
 {
     using (RacheliandDiniEntities3 db = new RacheliandDiniEntities3())
     {
         foreach (var item in db.Students)
         {
             if (item.StudentId == id)
             {
                 db.Students.Remove(item);
             }
         }
         foreach (var item in db.Users)
         {
             if (item.userId == id)
             {
                 db.Users.Remove(item);
             }
         }
     }
 }