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 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 #3
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);
        }