Example #1
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();
            }
        }
Example #2
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();
            }
        }
Example #3
0
        /// <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;
        }