예제 #1
0
        public static void UpdateGroup(int groupID, int teacherID, string subject, string gradeSection, string description)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                //get gradeID using gradeSection
                int gradeID = (from grade in context.Grades where grade.GradeNo + grade.Section == gradeSection select grade.GradeID).FirstOrDefault();
                if (gradeID == 0)
                {
                    throw new ArgumentOutOfRangeException("Grade name is invalid!");
                }
                //get subjectID
                int subjID = (from subj in context.Subjects where subj.Title == subject select subj.SubjectID).FirstOrDefault();
                if (subjID == 0)
                {
                    throw new ArgumentOutOfRangeException("Subject title is invalid!");
                }


                Group groupToUpdate = context.Set <Group>().Find(groupID);

                groupToUpdate.GroupID     = groupID;
                groupToUpdate.GradeID     = gradeID;
                groupToUpdate.SubjectID   = subjID;
                groupToUpdate.TeacherID   = teacherID;
                groupToUpdate.Description = description;
                context.SaveChanges();
            }
        }
예제 #2
0
        public static void UpdateUserInfo(UserInfo userInfo)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set <User>().Find(userInfo.UserID);
                userToUpdate.UserID     = userInfo.UserID;
                userToUpdate.LastName   = userInfo.LastName;
                userToUpdate.FirstName  = userInfo.FirstName;
                userToUpdate.Patronymic = userInfo.Patronymic;
                if (userToUpdate.Password == userInfo.Password) //password supplied is crypted already
                {
                    //do nothing - passwords already the same
                }
                else
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(userInfo.Password);
                }
                if (!Util.IsValidEmail(userInfo.Email))
                {
                    throw new ArgumentException("Email string is not a valid email!");
                }
                userToUpdate.Email       = userInfo.Email;
                userToUpdate.Phone       = userInfo.Phone;
                userToUpdate.DateOfBirth = userInfo.DoB;

                context.SaveChanges();
            }
        }
예제 #3
0
 /// <summary>
 /// Changes user password
 /// </summary>
 /// <param name="UserID">UserID</param>
 /// <param name="oldPass">old plain text password</param>
 /// <param name="newPass">new plain text password</param>
 public static void ChangeUserPassword(int UserID, string oldPass, string newPass)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         if (newPass.Length > 0)
         {
             User userToUpdate = (User)context.Set <User>().Find(UserID);
             //if (userToUpdate.Password.Equals(oldPass))
             if (Crypter.CheckPassword(oldPass, userToUpdate.Password))
             {
                 //userToUpdate.Password = newPass;
                 userToUpdate.Password = Crypter.Blowfish.Crypt(newPass);
                 context.SaveChanges();
             }
             else
             {
                 throw new ArgumentException("Old password is incorrect!");
             }
         }
         else
         {
             throw new ArgumentOutOfRangeException("New password is empty!");
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Updates a user
        /// </summary>
        /// <param name="u">New passwords supplied should be plain text!</param>
        public static void UpdateUser(UserInfo u)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set <User>().Find(u.UserID);

                if (userToUpdate == null)
                {
                    throw new ArgumentException("UserID is incorrect!");
                }
                userToUpdate.FirstName   = u.FirstName;
                userToUpdate.LastName    = u.LastName;
                userToUpdate.Patronymic  = u.Patronymic;
                userToUpdate.DateOfBirth = u.DoB;
                if (!Util.IsValidEmail(u.Email))
                {
                    throw new ArgumentException("Email string is not a valid email!");
                }
                userToUpdate.Email = u.Email;
                if (userToUpdate.Password != u.Password) //new password supplied => crypt it!
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(u.Password);
                }
                userToUpdate.Phone = u.Phone;

                context.SaveChanges();
            }
        }
예제 #5
0
        public static void UpdateStudent(StudentInfo si)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Student s = context.Set <Student>().Find(si.StudentID);
                if (s == null)
                {
                    throw new ArgumentNullException("StudentID to update cannot be null!");
                }

                if (!Util.IsValidEmail(si.Email))
                {
                    throw new ArgumentException("Email string is not a valid email!");
                }

                UsersDAL.UpdateUser(si);

                s.DateOfJoin = si.DateOfJoin;
                //find grade ID
                var gID = (from grade in context.Grades where (grade.GradeNo + grade.Section).Equals(si.GradeName) select grade.GradeID);
                if (gID.Count() > 0)
                {
                    s.GradeID = gID.First();
                }
                else
                {
                    throw new ArgumentException("Invalid grade name!");
                }
                context.SaveChanges();
            }
        }
예제 #6
0
        public static void DeleteParent(int parentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Parent parentToDelete = context.Set<Parent>().Find(parentID);

                context.Parents.Remove(parentToDelete);
                context.SaveChanges();
            }
        }
예제 #7
0
        public static void DeleteParent(int parentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Parent parentToDelete = context.Set <Parent>().Find(parentID);

                context.Parents.Remove(parentToDelete);
                context.SaveChanges();
            }
        }
예제 #8
0
        public static void UpdateGroup(int groupID, string description)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Group groupToUpdate = context.Set <Group>().Find(groupID);

                groupToUpdate.GroupID     = groupID;
                groupToUpdate.Description = description;
                context.SaveChanges();
            }
        }
예제 #9
0
        public static void UpdateTeacher(TeacherInfo t)
        {
            if (!Util.IsValidEmail(t.Email))
                throw new ArgumentException("Email string is not a valid email!");

            UsersDAL.UpdateUser(t);
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Teacher teacherToUpdate = context.Set<Teacher>().Find(t.TeacherID);
                teacherToUpdate.Specialization = t.Specialization;
                teacherToUpdate.Category = t.Category;
                context.SaveChanges();
            }
        }
예제 #10
0
        public static ParentInfo GetParentInfo(int parentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Parent p = context.Set<Parent>().Find(parentID);

                if (p != null)
                {
                    ParentInfo info = new ParentInfo(p);
                    return info;
                }
                else throw new ArgumentOutOfRangeException("Parent ID was not found in the DB!");
            }
        }
예제 #11
0
        public static void DeleteUser(int userID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToDelete = (User)context.Set<User>().Find(userID);

                if (userToDelete != null)
                {
                    context.Users.Remove(userToDelete);
                    context.SaveChanges();
                }
                else throw new ArgumentOutOfRangeException("Invalid userID!");

            }
        }
예제 #12
0
        public static int GetStudentGradeID(int studentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Student s = context.Set <Student>().Find(studentID);

                if (s != null)
                {
                    return(s.GradeID);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("No such studentID=" + studentID);
                }
            }
        }
예제 #13
0
        public static void UpdateTeacher(TeacherInfo t)
        {
            if (!Util.IsValidEmail(t.Email))
            {
                throw new ArgumentException("Email string is not a valid email!");
            }

            UsersDAL.UpdateUser(t);
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Teacher teacherToUpdate = context.Set <Teacher>().Find(t.TeacherID);
                teacherToUpdate.Specialization = t.Specialization;
                teacherToUpdate.Category       = t.Category;
                context.SaveChanges();
            }
        }
예제 #14
0
        public static StudentInfo GetStudentInfo(int studentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Student p = context.Set <Student>().Find(studentID);

                if (p != null)
                {
                    StudentInfo info = new StudentInfo(p);
                    return(info);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Student ID was not found in the DB!");
                }
            }
        }
예제 #15
0
        public static void DeleteUser(int userID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToDelete = (User)context.Set <User>().Find(userID);

                if (userToDelete != null)
                {
                    context.Users.Remove(userToDelete);
                    context.SaveChanges();
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid userID!");
                }
            }
        }
예제 #16
0
 /// <summary>
 /// Changes user password
 /// </summary>
 /// <param name="UserID">UserID</param>
 /// <param name="oldPass">old plain text password</param>
 /// <param name="newPass">new plain text password</param>
 public static void ChangeUserPassword(int UserID, string oldPass, string newPass)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         if (newPass.Length > 0)
         {
             User userToUpdate = (User)context.Set<User>().Find(UserID);
             //if (userToUpdate.Password.Equals(oldPass))
             if(Crypter.CheckPassword(oldPass, userToUpdate.Password))
             {
                 //userToUpdate.Password = newPass;
                 userToUpdate.Password = Crypter.Blowfish.Crypt(newPass);
                 context.SaveChanges();
             }
             else throw new ArgumentException("Old password is incorrect!");
         }
         else throw new ArgumentOutOfRangeException("New password is empty!");
     }
 }
예제 #17
0
        public static void UpdateGroup(int groupID, int teacherID, string subject, string gradeSection, string description)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                //get gradeID using gradeSection
                int gradeID = (from grade in context.Grades where grade.GradeNo + grade.Section == gradeSection select grade.GradeID).FirstOrDefault();
                if (gradeID == 0)
                    throw new ArgumentOutOfRangeException("Grade name is invalid!");
                //get subjectID
                int subjID = (from subj in context.Subjects where subj.Title == subject select subj.SubjectID).FirstOrDefault();
                if (subjID == 0)
                    throw new ArgumentOutOfRangeException("Subject title is invalid!");

                Group groupToUpdate = context.Set<Group>().Find(groupID);

                groupToUpdate.GroupID = groupID;
                groupToUpdate.GradeID = gradeID;
                groupToUpdate.SubjectID = subjID;
                groupToUpdate.TeacherID = teacherID;
                groupToUpdate.Description = description;
                context.SaveChanges();
            }
        }
예제 #18
0
        /// <summary>
        /// Updates a user
        /// </summary>
        /// <param name="u">New passwords supplied should be plain text!</param>
        public static void UpdateUser(UserInfo u)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set<User>().Find(u.UserID);

                if(userToUpdate==null)
                    throw new ArgumentException("UserID is incorrect!");
                userToUpdate.FirstName = u.FirstName;
                userToUpdate.LastName = u.LastName;
                userToUpdate.Patronymic = u.Patronymic;
                userToUpdate.DateOfBirth = u.DoB;
                if (!Util.IsValidEmail(u.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                userToUpdate.Email = u.Email;
                if (userToUpdate.Password != u.Password) //new password supplied => crypt it!
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(u.Password);
                }
                userToUpdate.Phone = u.Phone;

                context.SaveChanges();
            }
        }
예제 #19
0
        public static void UpdateGroup(int groupID, string description)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Group groupToUpdate = context.Set<Group>().Find(groupID);

                groupToUpdate.GroupID = groupID;
                groupToUpdate.Description = description;
                context.SaveChanges();
            }
        }
예제 #20
0
        public static void UpdateUserInfo(UserInfo userInfo)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set<User>().Find(userInfo.UserID);
                userToUpdate.UserID = userInfo.UserID;
                userToUpdate.LastName = userInfo.LastName;
                userToUpdate.FirstName = userInfo.FirstName;
                userToUpdate.Patronymic = userInfo.Patronymic;
                if (userToUpdate.Password == userInfo.Password) //password supplied is crypted already
                {
                    //do nothing - passwords already the same
                }
                else
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(userInfo.Password);
                }
                if (!Util.IsValidEmail(userInfo.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                userToUpdate.Email = userInfo.Email;
                userToUpdate.Phone = userInfo.Phone;
                userToUpdate.DateOfBirth = userInfo.DoB;

                context.SaveChanges();
            }
        }
예제 #21
0
        public static void UpdateStudent(StudentInfo si)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {

                Student s = context.Set<Student>().Find(si.StudentID);
                if (s == null)
                    throw new ArgumentNullException("StudentID to update cannot be null!");

                if (!Util.IsValidEmail(si.Email))
                    throw new ArgumentException("Email string is not a valid email!");

                UsersDAL.UpdateUser(si);

                s.DateOfJoin = si.DateOfJoin;
                //find grade ID
                var gID = (from grade in context.Grades where (grade.GradeNo+grade.Section).Equals(si.GradeName) select grade.GradeID);
                if (gID.Count() > 0)
                {
                    s.GradeID = gID.First();
                }
                else throw new ArgumentException("Invalid grade name!");
                context.SaveChanges();
            }
        }
예제 #22
0
        public static int GetStudentGradeID(int studentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Student s = context.Set<Student>().Find(studentID);

                if (s != null)
                {
                    return s.GradeID;
                }
                else throw new ArgumentOutOfRangeException("No such studentID=" + studentID);
            }
        }