private void DoChangePassword(string oldPassword, string newPassword, string retryPassword)
 {
     if (newPassword == retryPassword)
     {
         using (var context = new Classmaister5000Entities())
         {
             var user = context.Users.Find(UIRepository.Instance.CurrentClientId);
             if (oldPassword == user.Password)
             {
                 if (newPassword != user.Password)
                 {
                     user.Password             = newPassword;
                     context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                     context.SaveChanges();
                     MessageBox.Show("Password changed successfully!");
                     Application.Current.Windows[1].Close();
                 }
                 else
                 {
                     MessageBox.Show("The new password cannot be the old password!");
                 }
             }
             else
             {
                 MessageBox.Show("Your old password doesn't match!");
             }
         }
     }
     else
     {
         MessageBox.Show("The two passwords doesn't match!");
     }
 }
Beispiel #2
0
        public static bool AddToTimetable(int courseId)
        {
            using (var context = new Classmaister5000Entities())
            {
                var course = context.Courses.Find(courseId);
                ICollection <Timetable> records = context.Timetables.ToList();
                ICollection <Course>    courses = new List <Course>();
                foreach (var item in records)
                {
                    courses.Add(context.Courses.Where(c => c.Id == item.Course_Id).First());
                }

                bool   exists     = false;
                Course changeThis = null;
                foreach (var item in courses)
                {
                    if (item.Subject_Id == course.Subject_Id)
                    {
                        exists     = true;
                        changeThis = item;
                    }
                }
                if (!exists)
                {
                    int?id = context.Timetables.Max(i => (int?)i.Id) + 1;
                    if (id == null)
                    {
                        id = 0;
                    }
                    TimetableModel record = new TimetableModel();
                    record.UserId   = GetUserId;
                    record.CourseId = courseId;
                    record.Id       = (int)id + 1;

                    context.Timetables.Add(TimetableMapper.ModelToEntity(record));
                    context.SaveChanges();
                }
                else
                {
                    var changeThisPlease = context.Timetables.Where(t => t.Course_Id == changeThis.Id).First();
                    changeThisPlease.Course_Id            = courseId;
                    context.Entry(changeThisPlease).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
            return(true);
        }
Beispiel #3
0
 public static void DeleteCourse(int id)
 {
     using (var context = new Classmaister5000Entities())
     {
         var deleteThis = context.Courses.Where(c => c.Id == id).First();
         TimetableActions.RemoveFromTimetableByCourseId(id);
         context.Courses.Remove(deleteThis);
         context.SaveChanges();
     }
 }
Beispiel #4
0
 public static void UserLogout()
 {
     using (var context = new Classmaister5000Entities())
     {
         var CurrentUser = context.Users.Where(u => u.Id == UIRepository.Instance.CurrentClientId).First();
         CurrentUser.LastLogin            = DateTime.Now;
         context.Entry(CurrentUser).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     UIRepository.Instance.CurrentClientId = 0;
 }
Beispiel #5
0
        public static bool RemoveFromTimetableByCourseId(int courseId)
        {
            using (var context = new Classmaister5000Entities())
            {
                ICollection <Timetable> removeThese = context.Timetables.Where(c => c.Course_Id == courseId).ToList();
                context.Timetables.RemoveRange(removeThese);
                context.SaveChanges();
            }

            return(true);
        }
Beispiel #6
0
        public static bool RemoveFromTimetable(int id)
        {
            using (var context = new Classmaister5000Entities())
            {
                Timetable removeThis = context.Timetables.Find(id);
                context.Timetables.Remove(removeThis);
                context.SaveChanges();
            }

            return(true);
        }
Beispiel #7
0
 public static bool CourseAdd(string name, string teacher, string room, int dayId, DateTime from, DateTime to, int subjectId)
 {
     if (!HasCourse(name, subjectId))
     {
         if (from.Hour < to.Hour)
         {
             if (!IsTeacherBusy(teacher, dayId, from, to))
             {
                 using (var context = new Classmaister5000Entities())
                 {
                     //CourseModel newCourse = new CourseModel();
                     //newCourse.Name = name;
                     //newCourse.Teacher = teacher;
                     //newCourse.Room = room;
                     //newCourse.Day_Id = dayId;
                     //newCourse.From = from;
                     //newCourse.To = to;
                     //newCourse.Subject_Id = subjectId;
                     //context.Courses.Add(CourseMapper.ModelToEntity(newCourse));
                     Course newCourse = new Course();
                     newCourse.Day_Id     = dayId;
                     newCourse.Room       = room;
                     newCourse.Teacher    = teacher;
                     newCourse.Name       = name;
                     newCourse.Subject_Id = subjectId;
                     newCourse.From       = from;
                     newCourse.To         = to;
                     context.Courses.Add(newCourse);
                     context.SaveChanges();
                     return(true);
                 }
             }
             else
             {
                 throw new TeacherBusyException();
             }
         }
         else
         {
             throw new InvalidTimeException();
         }
     }
     else
     {
         throw new CourseAlreadyExistsException();
     }
 }
Beispiel #8
0
 public static bool SubjectAdd(string Name, bool IsLecture)
 {
     if (!HasSubjectName(Name))
     {
         using (var context = new Classmaister5000Entities())
         {
             SubjectModel newSubject = new SubjectModel();
             newSubject.SubjectName = Name;
             newSubject.IsLecture   = IsLecture;
             newSubject.User_Id     = GetUserId;
             context.Subjects.Add(SubjectMapper.ModelToEntity(newSubject));
             context.SaveChanges();
             return(true);
         }
     }
     else
     {
         throw new SubjectAlreadyExistsException();
     }
 }
 public static void RegisterUser(string username, string password, string RetryPassword,
                                 string FirstName, string LastName)
 {
     using (var context = new Classmaister5000Entities())
     {
         if (HasUserName(username))
         {
             throw new UsernameAlreadyExistsException();
         }
         else if (password == RetryPassword)
         {
             UserModel NewUser = new UserModel(FirstName, LastName, username, password);
             context.Users.Add(UserMapper.ModelToEntity(NewUser));
             context.SaveChanges();
         }
         else
         {
             throw new PasswordsNotEqualsException();
         }
     }
 }
Beispiel #10
0
 public static bool SubjectRemove(string Name)
 {
     if (HasSubjectName(Name))
     {
         using (var context = new Classmaister5000Entities())
         {
             Subject removeThis = context.Subjects.Where(s => s.SubjectName.ToLower() == Name.ToLower()).First();
             ICollection <Course> removeTheseCourses = removeThis.Courses;
             foreach (var item in removeTheseCourses)
             {
                 TimetableActions.RemoveFromTimetableByCourseId(item.Id);
             }
             context.Courses.RemoveRange(removeTheseCourses);
             context.Subjects.Remove(removeThis);
             context.SaveChanges();
             return(true);
         }
     }
     else
     {
         throw new SubjectNotExistsException();
     }
 }