Exemplo n.º 1
0
        public static User_Role Create(User_Role source)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                User_Role ur = new User_Role();
                try
                {
                    ur.CreatedBy        = source.CreatedBy;
                    ur.CreatedDateTime  = DateTime.Now;
                    ur.IsActive         = true;
                    ur.ModifiedBy       = source.ModifiedBy;
                    ur.ModifiedDateTime = DateTime.Now;
                    ur.Role_ID          = source.Role_ID;
                    ur.User_ID          = source.User_ID;

                    dbContext.User_Role.Add(ur);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
                return(ur);
            }
        }
Exemplo n.º 2
0
 public static User GetUser(this User_Role context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Users.FirstOrDefault(u => u.IsActive && u.User_ID.Equals(context.User_ID)));
     }
 }
Exemplo n.º 3
0
 public static List <Role> GetAllRoles()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Roles.Where(r => r.IsActive).ToList());
     }
 }
Exemplo n.º 4
0
 public static Role GetRole(this User context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.User_Role.FirstOrDefault(u => u.IsActive && u.User_ID == context.User_ID).GetRole());
     }
 }
Exemplo n.º 5
0
 public static Student_Course GetStudentCourse(this User context, Course_Schedule schedule)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Student_Course.FirstOrDefault(sc => sc.IsActive && sc.User_ID.Equals(context.User_ID) && sc.CourseSchedule_ID.Equals(schedule.CourseSchedule_ID)));
     }
 }
Exemplo n.º 6
0
 public static Role GetRole(this User_Role context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Roles.FirstOrDefault(r => r.IsActive && r.Role_ID.Equals(context.Role_ID)));
     }
 }
Exemplo n.º 7
0
        public static List <Course_Schedule> GetSchedulesOf(User user, RoleTypes roleType)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                //Check role type
                if (roleType == RoleTypes.Student)
                {
                    //Find all student course object with the user's id
                    var selections = dbContext.Student_Course.Where(sc => sc.User_ID.Equals(user.User_ID) && sc.IsActive);

                    //Convert student_course to course_schedule
                    List <Course_Schedule> courseSchedules = new List <Course_Schedule>();
                    foreach (Student_Course sc in selections)
                    {
                        Course_Schedule cs = sc.GetSchedule();
                        if (cs != null)
                        {
                            courseSchedules.Add(cs);
                        }
                    }

                    //Return the list
                    return(courseSchedules);
                }
                else
                {
                    //Return all course_schedules where its teacher_id equals the given user's id.
                    var selections = dbContext.Course_Schedule.Where(s => s.Teacher_ID.Equals(user.User_ID) && s.IsActive);
                    return(selections.ToList());
                }
            }
        }
Exemplo n.º 8
0
 public static List <Faculty> GetAll()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Faculties.Where(f => f.IsActive).ToList());
     }
 }
Exemplo n.º 9
0
 public static List <Student_Course> GetStudentCourses(this Course_Schedule context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Student_Course.Where(sc => sc.IsActive && sc.CourseSchedule_ID.Equals(context.CourseSchedule_ID)).ToList());
     }
 }
Exemplo n.º 10
0
        public static User Create(User source)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                //Create instance of new user and set values from source
                User user = new User();
                try
                {
                    user.Address          = source.Address;
                    user.ContactNumber    = source.ContactNumber;
                    user.CreatedBy        = source.CreatedBy;
                    user.CreatedDateTime  = DateTime.Now;
                    user.DateOfBirth      = source.DateOfBirth;
                    user.Email            = source.Email;
                    user.FirstName        = source.FirstName;
                    user.FullName         = source.FullName;
                    user.IsActive         = true;
                    user.LastName         = source.LastName;
                    user.ModifiedBy       = source.ModifiedBy;
                    user.ModifiedDateTime = DateTime.Now;
                    user.Password         = source.Password;
                    user.Student_ID       = source.Student_ID;

                    //Add the new user to DB and apply change
                    dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(null);
                }
                return(user);
            }
        }
Exemplo n.º 11
0
 public static Course_Schedule GetSchedule(this Student_Course context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Course_Schedule.FirstOrDefault(s => s.IsActive && s.CourseSchedule_ID.Equals(context.CourseSchedule_ID)));
     }
 }
Exemplo n.º 12
0
 public static List <Course> GetAllCourses()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Courses.Where(c => c.IsActive).ToList());
     }
 }
Exemplo n.º 13
0
 public static Faculty GetFaculty(this Course context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Faculties.FirstOrDefault(f => f.IsActive && f.Faculty_ID.Equals(context.Faculty_ID)));
     }
 }
Exemplo n.º 14
0
 public static User GetStudent(this Student_Course context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Users.FirstOrDefault(u => u.User_ID.Equals(context.User_ID) && u.IsActive));
     }
 }
Exemplo n.º 15
0
 public static List <Course_Schedule> GetSchedules(this Course context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Course_Schedule.Where(cs => cs.IsActive && cs.Course_ID.Equals(context.Course_ID)).ToList());
     }
 }
Exemplo n.º 16
0
 public static Course GetCourse(this Course_Schedule context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Courses.FirstOrDefault(c => c.Course_ID.Equals(context.Course_ID) && c.IsActive));
     }
 }
Exemplo n.º 17
0
 public static User GetTutor(this Course_Schedule context)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Users.FirstOrDefault(t => t.User_ID.Equals(context.Teacher_ID) && t.IsActive));
     }
 }
Exemplo n.º 18
0
 public static bool IsEnrolled(this User context, Course course)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Student_Course.FirstOrDefault(c => c.IsActive && c.GetCourse().Course_ID.Equals(course.Course_ID) && c.User_ID.Equals(context.User_ID)) != null);
     }
 }
Exemplo n.º 19
0
        public static bool Create(Course source)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                try
                {
                    Course course = new Course();

                    course.Course_Code        = source.Course_Code;
                    course.Course_Description = source.Course_Description;
                    course.Course_Name        = source.Course_Name;
                    course.CreatedBy          = source.CreatedBy;
                    course.CreatedDateTime    = DateTime.Now;
                    course.Faculty_ID         = source.Faculty_ID;
                    course.IsActive           = true;
                    course.ModifiedBy         = source.ModifiedBy;
                    course.ModifiedDateTime   = DateTime.Now;

                    dbContext.Courses.Add(course);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 20
0
        public static bool Create(Course_Schedule source)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                try
                {
                    Course_Schedule schedule = new Course_Schedule();

                    schedule.Course_ID        = source.Course_ID;
                    schedule.CreatedBy        = source.CreatedBy;
                    schedule.CreatedDateTime  = DateTime.Now;
                    schedule.DT_From          = source.DT_From;
                    schedule.DT_To            = source.DT_To;
                    schedule.IsActive         = true;
                    schedule.ModifiedBy       = source.ModifiedBy;
                    schedule.ModifiedDateTime = DateTime.Now;
                    schedule.Teacher_ID       = source.Teacher_ID;

                    dbContext.Course_Schedule.Add(schedule);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 21
0
 public static int GetCourseCount()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         return(dbContext.Courses.Where(c => c.IsActive).Count());
     }
 }
Exemplo n.º 22
0
        public static bool Create(Student_Course source)
        {
            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                try
                {
                    Student_Course sc = new Student_Course();

                    sc.CourseSchedule_ID = source.CourseSchedule_ID;
                    sc.CreatedBy         = source.CreatedBy;
                    sc.CreatedDateTime   = DateTime.Now;
                    sc.IsActive          = true;
                    sc.ModifiedBy        = source.ModifiedBy;
                    sc.ModifiedDateTime  = DateTime.Now;
                    sc.User_ID           = source.User_ID;
                    sc.Grade             = source.Grade;

                    dbContext.Student_Course.Add(sc);
                    dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 23
0
 public static RoleTypes GetRoleOf(User user)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         var selection = dbContext.User_Role.FirstOrDefault(u => u.IsActive && u.User_ID == user.User_ID);
         return((RoleTypes)selection.Role_ID);
     }
 }
Exemplo n.º 24
0
 public static List <Course_Schedule> GetAllSchedules()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         //Get all schedules and return
         return(dbContext.Course_Schedule.Where(cs => cs.IsActive).ToList());
     }
 }
Exemplo n.º 25
0
 public static List <User> GetAllUsers()
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         //Return all users
         return(dbContext.Users.Where(u => u.IsActive).ToList());
     }
 }
Exemplo n.º 26
0
 public static void Delete(User user)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         dbContext.Users.Remove(user);
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 27
0
 public static User Exists(string username)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         //Check if a user exists with given username and pw.
         return(dbContext.Users.FirstOrDefault(user => user.Student_ID.Equals(username) && user.IsActive));
     }
 }
Exemplo n.º 28
0
        public static User Login(string username, string password)
        {
            password = Renko.MD5Encryption.Encrypt(password);

            using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
            {
                return(dbContext.Users.FirstOrDefault(user => user.Student_ID.Equals(username) && password.Equals(user.Password) && user.IsActive));
            }
        }
Exemplo n.º 29
0
 public static List <Student_Course> GetStudentCoursesOf(User user)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         //Return all course_schedules where its teacher_id equals the given user's id.
         var selections = dbContext.Student_Course.Where(s => s.User_ID.Equals(user.User_ID) && s.IsActive);
         return(selections.ToList());
     }
 }
Exemplo n.º 30
0
 public static void DoDBOperation(Action <KeunhongInstituteDBEntities> operation, Action <Exception> onCatch = null)
 {
     using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities())
     {
         try
         {
             operation(dbContext);
         }
         catch (Exception e)
         {
             onCatch(e);
         }
     }
 }