コード例 #1
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #2
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #3
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
 /// <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
        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();
            }
        }
コード例 #5
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        /// <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();
            }
        }
コード例 #6
0
ファイル: TeacherDAL.cs プロジェクト: yuryk53/SchoolJournal
        /// <summary>
        /// Adds new teacher to the database.
        /// </summary>
        /// <param name="t"></param>
        /// <returns>ID of newly added teacher.</returns>
        public static int AddNewTeacher(TeacherInfo t)
        {
            int userID;

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

            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    userID = UsersDAL.AddNewUser(t, dbContextTransaction.UnderlyingTransaction);
                    context.Teachers.Add(new Teacher
                    {
                        TeacherID      = userID,
                        Category       = t.Category,
                        Specialization = t.Specialization
                    });
                    context.SaveChanges();
                    dbContextTransaction.Commit();
                }
            }
            return(userID);
        }
コード例 #7
0
        public static int NewGroup(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 newGroup = new Group
                {
                    TeacherID   = teacherID,
                    SubjectID   = subjID,
                    GradeID     = gradeID,
                    Description = description
                };

                context.Groups.Add(newGroup);
                context.SaveChanges();

                return(newGroup.GroupID);
            }
        }
コード例 #8
0
ファイル: LessonDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static void PlaceMark(int lessonID, int studentID, decimal? markValue, bool isPresent = true)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                try
                {
                    //context.placeMark(lessonID, studentID, markValue, isPresent);
                    int markID = -1;
                    if (markValue.HasValue) //check for correct value
                    {
                        var value = from mark in context.Marks
                                     where mark.Value == markValue
                                     select mark;
                        if (value.Count() == 0)
                            throw new ArgumentOutOfRangeException(string.Format("Mark value '{0}' is incorrect!", markValue));
                        markID = value.First().MarkID;
                    }

                    var less_student = from record in context.lesson_student
                                       where record.LessonID == lessonID &&
                                             record.StudentID == studentID
                                       select record;
                    if (markID != -1)
                        less_student.First().MarkID = markID;
                    less_student.First().IsPresent = isPresent;

                    context.SaveChanges();
                }
                catch (Exception ex)
                {

                    throw new Exception("PlaceMark failed!"+ex.Message+"\n"+ex.InnerException.Message);
                }
            }
        }
コード例 #9
0
ファイル: GroupDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static int NewGroup(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 newGroup = new Group
                    {
                        TeacherID = teacherID,
                        SubjectID = subjID,
                        GradeID = gradeID,
                        Description = description
                    };

                    context.Groups.Add(newGroup);
                    context.SaveChanges();

                    return newGroup.GroupID;
            }
        }
コード例 #10
0
 public static void AddStudentToGroup(int groupID, int studentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand(
             string.Format("INSERT INTO student_group(group_id,student_id) VALUES({0},{1})", groupID, studentID));
         context.SaveChanges();
     }
 }
コード例 #11
0
 public static void RemoveStudentFromGroup(int groupID, int studentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM student_group WHERE group_id=@group_id AND student_id=@student_id",
                                            new SqlParameter("@group_id", groupID), new SqlParameter("@student_id", studentID));
         context.SaveChanges();
     }
 }
コード例 #12
0
ファイル: GroupDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void RemoveStudentFromGroup(int groupID, int studentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM student_group WHERE group_id=@group_id AND student_id=@student_id",
             new SqlParameter("@group_id", groupID), new SqlParameter("@student_id", studentID));
         context.SaveChanges();
     }
 }
コード例 #13
0
ファイル: GroupDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void AddStudentToGroup(int groupID, int studentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand(
             string.Format("INSERT INTO student_group(group_id,student_id) VALUES({0},{1})",groupID,studentID));
         context.SaveChanges();
     }
 }
コード例 #14
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void RemoveParent(int studentID, int parentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM parent_student WHERE student_id=@studentID AND parent_id=@parentID",
                                            new SqlParameter("@studentID", studentID),
                                            new SqlParameter("@parentID", parentID));
         context.SaveChanges();
     }
 }
コード例 #15
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void AddParent(int studentID, int parentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("INSERT INTO parent_student VALUES (@student_id, @parent_id)",
                                            new SqlParameter("@student_id", studentID),
                                            new SqlParameter("@parent_id", parentID));
         context.SaveChanges();
     }
 }
コード例 #16
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();
            }
        }
コード例 #17
0
ファイル: ParentDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static void DeleteParent(int parentID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                Parent parentToDelete = context.Set<Parent>().Find(parentID);

                context.Parents.Remove(parentToDelete);
                context.SaveChanges();
            }
        }
コード例 #18
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();
            }
        }
コード例 #19
0
ファイル: ParentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static int AddNewParent(Parent newParent)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         if (!Util.IsValidEmail(newParent.user.Email))
             throw new ArgumentException("Email string is not a valid email!");
         context.Parents.Add(newParent);
         context.SaveChanges();
         return newParent.ParentID;
     }
 }
コード例 #20
0
 public static int AddNewParent(Parent newParent)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         if (!Util.IsValidEmail(newParent.user.Email))
         {
             throw new ArgumentException("Email string is not a valid email!");
         }
         context.Parents.Add(newParent);
         context.SaveChanges();
         return(newParent.ParentID);
     }
 }
コード例 #21
0
ファイル: TeacherDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #22
0
        public static ILessonInfo StartNewLesson(string subj_title, string theme, int numberOfHours, string gradeName, string homeTask, int teacherID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                ObjectParameter output = new ObjectParameter("addedLesson_id", typeof(int));
                context.startNewLesson(subj_title, theme, numberOfHours, gradeName, homeTask, teacherID, output);
                context.SaveChanges();

                int lessonID = (int)output.Value;

                var lsn = (from lesson in context.Lessons where lesson.LessonID == lessonID select lesson).FirstOrDefault();
                return(new LessonInfo(lsn));
            }
        }
コード例 #23
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        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!");

            }
        }
コード例 #24
0
ファイル: TeacherDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #25
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        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!");
                }
            }
        }
コード例 #26
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        //returns new UserID
        public static int AddNewUser(UserInfo u, System.Data.Common.DbTransaction transaction = null)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                if (transaction != null)
                {
                    context.Database.UseTransaction(transaction);
                }
                User newUser = u.GetUser();
                if (!Util.IsValidEmail(u.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                newUser.Password = Crypter.Blowfish.Crypt(newUser.Password); //newUser entity contains uncrypted password!
                context.Users.Add(newUser);
                context.SaveChanges();

                return newUser.UserID;
            }
        }
コード例 #27
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void ShiftAllStudentsToNextGrade()
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 foreach (Student s in context.Students)
                 {
                     //if the current grade is the last one, the student is deleted!
                     int nextGradeID = GetNextGradeID(s.GradeID);
                     if (nextGradeID == -1) //delete student from school
                     {
                         UsersDAL.DeleteUser(s.StudentID);
                     }
                     else
                     {
                         s.GradeID = nextGradeID;
                     }
                 }
                 foreach (Group g in context.Groups)
                 {
                     int nextGradeID = GetNextGradeID(g.GradeID);
                     if (nextGradeID == -1) //delete student from school
                     {
                         context.Groups.Remove(g);
                     }
                     else
                     {
                         g.GradeID = nextGradeID;
                     }
                 }
                 context.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 throw ex;
             }
         }
     }
 }
コード例 #28
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
 /// <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!");
     }
 }
コード例 #29
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static int AddNewUser(UserInfo u, System.Data.Common.DbTransaction transaction = null) //returns new UserID
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                if (transaction != null)
                {
                    context.Database.UseTransaction(transaction);
                }
                User newUser = u.GetUser();
                if (!Util.IsValidEmail(u.Email))
                {
                    throw new ArgumentException("Email string is not a valid email!");
                }
                newUser.Password = Crypter.Blowfish.Crypt(newUser.Password); //newUser entity contains uncrypted password!
                context.Users.Add(newUser);
                context.SaveChanges();

                return(newUser.UserID);
            }
        }
コード例 #30
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static int AddNewStudent(string firstName, string lastName, string patronymic, DateTime?dateOfBirth,
                                        string email, string password, string phone, string gradeName)
        {
            string cpassword = Crypter.Blowfish.Crypt(password);

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

                context.addNewStudent(firstName,
                                      lastName,
                                      patronymic,
                                      dateOfBirth,
                                      email,
                                      cpassword,
                                      phone,
                                      gradeName);

                context.SaveChanges();

                var users = (from user in context.Users
                             where user.FirstName == firstName &&
                             user.LastName == lastName &&
                             user.Patronymic == patronymic &&
                             user.DateOfBirth == dateOfBirth &&
                             user.Email == email &&
                             user.Phone == phone
                             select user).ToList();
                foreach (User user in users)
                {
                    if (user.Password == cpassword)
                    {
                        return(user.UserID);
                    }
                }
                return(-1);
            }
        }
コード例 #31
0
        public static void PlaceMark(int lessonID, int studentID, decimal?markValue, bool isPresent = true)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                try
                {
                    //context.placeMark(lessonID, studentID, markValue, isPresent);
                    int markID = -1;
                    if (markValue.HasValue) //check for correct value
                    {
                        var value = from mark in context.Marks
                                    where mark.Value == markValue
                                    select mark;
                        if (value.Count() == 0)
                        {
                            throw new ArgumentOutOfRangeException(string.Format("Mark value '{0}' is incorrect!", markValue));
                        }
                        markID = value.First().MarkID;
                    }

                    var less_student = from record in context.lesson_student
                                       where record.LessonID == lessonID &&
                                       record.StudentID == studentID
                                       select record;
                    if (markID != -1)
                    {
                        less_student.First().MarkID = markID;
                    }
                    less_student.First().IsPresent = isPresent;

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("PlaceMark failed!" + ex.Message + "\n" + ex.InnerException.Message);
                }
            }
        }
コード例 #32
0
ファイル: TeacherDAL.cs プロジェクト: yuryk53/SchoolJournal
        /// <summary>
        /// Adds new teacher to the database.
        /// </summary>
        /// <param name="t"></param>
        /// <returns>ID of newly added teacher.</returns>
        public static int AddNewTeacher(TeacherInfo t)
        {
            int userID;
            if (!Util.IsValidEmail(t.Email))
                throw new ArgumentException("Email string is not a valid email!");

            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    userID = UsersDAL.AddNewUser(t, dbContextTransaction.UnderlyingTransaction);
                    context.Teachers.Add(new Teacher
                    {
                        TeacherID = userID,
                        Category = t.Category,
                        Specialization = t.Specialization
                    });
                    context.SaveChanges();
                    dbContextTransaction.Commit();
                }
            }
            return userID;
        }
コード例 #33
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void RemoveParent(int studentID, int parentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM parent_student WHERE student_id=@studentID AND parent_id=@parentID",
             new SqlParameter("@studentID", studentID),
             new SqlParameter("@parentID", parentID));
         context.SaveChanges();
     }
 }
コード例 #34
0
ファイル: GroupDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #35
0
ファイル: GroupDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #36
0
ファイル: LessonDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static ILessonInfo StartNewLesson(string subj_title, string theme, int numberOfHours, string gradeName, string homeTask, int teacherID)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                ObjectParameter output = new ObjectParameter("addedLesson_id", typeof(int));
                context.startNewLesson(subj_title, theme, numberOfHours, gradeName, homeTask, teacherID, output);
                context.SaveChanges();

                int lessonID = (int)output.Value;

                var lsn = (from lesson in context.Lessons where lesson.LessonID==lessonID select lesson).FirstOrDefault();
                return new LessonInfo(lsn);
            }
        }
コード例 #37
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void AddParent(int studentID, int parentID)
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         context.Database.ExecuteSqlCommand("INSERT INTO parent_student VALUES (@student_id, @parent_id)",
                                                         new SqlParameter("@student_id", studentID),
                                                         new SqlParameter("@parent_id", parentID));
         context.SaveChanges();
     }
 }
コード例 #38
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #39
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
        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();
            }
        }
コード例 #40
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
        public static int AddNewStudent(string firstName, string lastName, string patronymic, DateTime? dateOfBirth,
                                          string email, string password, string phone, string gradeName)
        {
            string cpassword = Crypter.Blowfish.Crypt(password);
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                if (!Util.IsValidEmail(email))
                    throw new ArgumentException("Email string is not a valid email!");

                context.addNewStudent(firstName,
                                      lastName,
                                      patronymic,
                                      dateOfBirth,
                                      email,
                                      cpassword,
                                      phone,
                                      gradeName);

                context.SaveChanges();

                var users = (from user in context.Users
                              where user.FirstName == firstName &&
                                    user.LastName == lastName &&
                                    user.Patronymic == patronymic &&
                                    user.DateOfBirth == dateOfBirth &&
                                    user.Email == email &&
                                    user.Phone == phone
                              select user).ToList();
                foreach (User user in users)
                {
                    if (user.Password==cpassword)
                        return user.UserID;
                }
                return -1;

            }
        }
コード例 #41
0
ファイル: StudentDAL.cs プロジェクト: yuryk53/SchoolJournal
 public static void ShiftAllStudentsToNextGrade()
 {
     using (SchoolJournalEntities context = new SchoolJournalEntities())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 foreach (Student s in context.Students)
                 {
                     //if the current grade is the last one, the student is deleted!
                     int nextGradeID = GetNextGradeID(s.GradeID);
                     if (nextGradeID == -1) //delete student from school
                     {
                         UsersDAL.DeleteUser(s.StudentID);
                     }
                     else
                     {
                         s.GradeID = nextGradeID;
                     }
                 }
                 foreach (Group g in context.Groups)
                 {
                     int nextGradeID = GetNextGradeID(g.GradeID);
                     if (nextGradeID == -1) //delete student from school
                     {
                         context.Groups.Remove(g);
                     }
                     else
                     {
                         g.GradeID = nextGradeID;
                     }
                 }
                 context.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
                 throw ex;
             }
         }
     }
 }
コード例 #42
0
ファイル: UsersDAL.cs プロジェクト: yuryk53/SchoolJournal
        /// <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();
            }
        }