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); } }
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))); } }
public static List <Role> GetAllRoles() { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Roles.Where(r => r.IsActive).ToList()); } }
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()); } }
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))); } }
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))); } }
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()); } } }
public static List <Faculty> GetAll() { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Faculties.Where(f => f.IsActive).ToList()); } }
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()); } }
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); } }
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))); } }
public static List <Course> GetAllCourses() { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Courses.Where(c => c.IsActive).ToList()); } }
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))); } }
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)); } }
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()); } }
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)); } }
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)); } }
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); } }
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); }
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); }
public static int GetCourseCount() { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { return(dbContext.Courses.Where(c => c.IsActive).Count()); } }
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); }
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); } }
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()); } }
public static List <User> GetAllUsers() { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { //Return all users return(dbContext.Users.Where(u => u.IsActive).ToList()); } }
public static void Delete(User user) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { dbContext.Users.Remove(user); dbContext.SaveChanges(); } }
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)); } }
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)); } }
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()); } }
public static void DoDBOperation(Action <KeunhongInstituteDBEntities> operation, Action <Exception> onCatch = null) { using (KeunhongInstituteDBEntities dbContext = new KeunhongInstituteDBEntities()) { try { operation(dbContext); } catch (Exception e) { onCatch(e); } } }