Exemple #1
0
 public User SelectById(int id)
 {
     using (CeLSDEntities entity = new CeLSDEntities())
     {
         return(entity.Users.Single <User>(p => p.UserId == id));
     }
 }
Exemple #2
0
        public List <CourseModel> GetMyCourses(int userId)
        {
            using (CeLSDEntities dbContext = new CeLSDEntities())
            {
                List <CourseModel> list = (from courses in dbContext.Courses
                                           join ca in dbContext.CoursesUsers on courses.CourseId equals ca.CourseId
                                           join user in dbContext.Users on ca.UserId equals user.UserId
                                           where user.UserId == userId
                                           select new CourseModel {
                    CourseName = courses.CourseName, ProfessorName = ca.User.UserName, CourseId = courses.CourseId
                }).ToList();

                var coursesList = GetCourses();

                foreach (var professor in coursesList)
                {
                    foreach (var courses in list)
                    {
                        if (professor.CourseId == courses.CourseId)
                        {
                            courses.ProfessorName = professor.ProfessorName;
                        }
                    }
                }
                return(list);
            }
        }
Exemple #3
0
        public string Update(int userId, string userName, string userEmail, string userPassword, int userType)
        {
            using (CeLSDEntities dbContext = new CeLSDEntities())
            {
                try
                {
                    dbContext.Database.Connection.Open();
                    User user = dbContext.Users.Single <User>(o => o.UserId == userId);



                    user.UserName     = userName;
                    user.UserEmail    = userEmail;
                    user.UserName     = userName;
                    user.UserPassword = md5.GetMd5Sum(userPassword);
                    user.UserType     = userType;

                    dbContext.SaveChanges();

                    return("Success");
                }
                catch (Exception exp)
                {
                    throw new Exception(exp.Message, exp);
                }
                finally
                {
                    dbContext.Database.Connection.Close();
                }
            }
        }
Exemple #4
0
 public User Login(string email, string password)
 {
     using (CeLSDEntities entity = new CeLSDEntities())
     {
         string pw = md5.GetMd5Sum(password);
         return(entity.Users.SingleOrDefault(p => p.UserEmail == email && p.UserPassword == pw));
     }
 }
Exemple #5
0
 public List <UserType> SelectAll()
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         return((from type in dbContext.UserTypes
                 select type).ToList());
     }
 }
Exemple #6
0
 public List <Topic> GetTopics(int id)
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         return((from courses in dbContext.Topics
                 where courses.CourseId == id
                 select courses).ToList());
     }
 }
Exemple #7
0
 public List <User> SelectAllProfessors()
 {
     using (CeLSDEntities entity = new CeLSDEntities())
     {
         return((from user in entity.Users
                 join type in entity.UserTypes on user.UserType equals type.UserTypeId
                 where user.UserType == 2
                 select user).ToList <User>());
     }
 }
Exemple #8
0
        public List <int> GetEnrollment(int userId, int courseId)
        {
            using (CeLSDEntities dbContext = new CeLSDEntities())
            {
                return((from courses in dbContext.Courses
                        join ca in dbContext.CoursesUsers on courseId equals ca.CourseId
                        join user in dbContext.Users on ca.UserId equals user.UserId
                        where user.UserType == 3 && courses.CourseId == courseId && user.UserId == userId

                        select courses.CourseId).ToList());
            }
        }
Exemple #9
0
 public List <CourseModel> GetCourses()
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         return((from courses in dbContext.Courses
                 join ca in dbContext.CoursesUsers on courses.CourseId equals ca.CourseId
                 join user in dbContext.Users on ca.UserId equals user.UserId
                 where user.UserType == 2
                 select new CourseModel {
             CourseName = courses.CourseName, ProfessorName = user.UserName, CourseId = courses.CourseId
         }).ToList());
     }
 }
Exemple #10
0
        public bool CheckEnroll(int userId, int courseId)
        {
            using (CeLSDEntities dbContext = new CeLSDEntities())
            {
                CoursesUser coursesUser = dbContext.CoursesUsers.SingleOrDefault(c => c.UserId == userId && c.CourseId == courseId);
                if (coursesUser == null)
                {
                    return(false);
                }

                return(true);
            }
        }
Exemple #11
0
 public List <UserModel> SelectAll()
 {
     using (CeLSDEntities entity = new CeLSDEntities())
     {
         return((from user in entity.Users
                 join type in entity.UserTypes on user.UserType equals type.UserTypeId
                 select new UserModel
         {
             UserId = user.UserId,
             UserEmail = user.UserEmail,
             UserName = user.UserName,
             UserPassowrd = user.UserPassword,
             UserType = type.Slug
         }).ToList <UserModel>());
     }
 }
Exemple #12
0
 public string UnEnroll(int userId, int courseId)
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         try
         {
             CoursesUser coursesUser = dbContext.CoursesUsers.Single <CoursesUser>(c => c.UserId == userId && c.CourseId == courseId);
             dbContext.CoursesUsers.Remove(coursesUser);
             dbContext.SaveChanges();
             return("Success");
         }
         catch (Exception e)
         {
             throw new Exception(e.InnerException.ToString());
         }
     }
 }
Exemple #13
0
        public string UpdatePassword(int userId, string userPassword)
        {
            using (CeLSDEntities dbContext = new CeLSDEntities())
            {
                try
                {
                    dbContext.Database.Connection.Open();
                    User user = dbContext.Users.Single <User>(o => o.UserId == userId);
                    user.UserPassword = md5.GetMd5Sum(userPassword);
                    dbContext.SaveChanges();

                    return("");
                }
                catch (Exception exp)
                {
                    throw new Exception(exp.Message, exp);
                }
            }
        }
Exemple #14
0
 public string Enroll(int userId, int courseId)
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         try
         {
             CoursesUser coursesUser = new CoursesUser()
             {
                 UserId   = userId,
                 CourseId = courseId
             };
             dbContext.CoursesUsers.Add(coursesUser);
             dbContext.SaveChanges();
             return("Success");
         }
         catch (Exception e)
         {
             throw new Exception(e.InnerException.ToString());
         }
     }
 }
Exemple #15
0
        public string Insert(string courseName, int profesorId)
        {
            using (CeLSDEntities dbcontext = new CeLSDEntities())
            {
                try
                {
                    Cours course = new Cours();
                    course.CourseName = courseName;


                    var n = dbcontext.Courses.Add(course);
                    dbcontext.SaveChanges();
                    var x = dbcontext.Courses.ToList().Last <Cours>();
                    InsertProfessor(x.CourseId, profesorId);
                    return("Success");
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
            }
        }
Exemple #16
0
 public string Insert(string topicName, string topicDocxname, int courseId)
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         try
         {
             Topic topic = new Topic()
             {
                 TopicsName = topicName,
                 TopicsFile = topicDocxname,
                 CourseId   = courseId
             };
             dbContext.Topics.Add(topic);
             dbContext.SaveChanges();
             return("Success");
         }
         catch (Exception exp)
         {
             throw new Exception(exp.Message, exp);
         }
     }
 }
Exemple #17
0
        public string Update(int courseId, string courseName)
        {
            using (CeLSDEntities dbcontext = new CeLSDEntities())
            {
                try
                {
                    dbcontext.Database.Connection.Open();
                    Cours course = dbcontext.Courses.Single <Cours>(c => c.CourseId == courseId);

                    course.CourseName = courseName;
                    return("Success");
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
                finally
                {
                    dbcontext.Database.Connection.Close();
                }
            }
        }
Exemple #18
0
 public string Delete(int courseId)
 {
     using (CeLSDEntities dbcontext = new CeLSDEntities())
     {
         try
         {
             dbcontext.Database.Connection.Open();
             Cours course = dbcontext.Courses.Single <Cours>(c => c.CourseId == courseId);
             dbcontext.Courses.Remove(course);
             dbcontext.SaveChanges();
             return("Success");
         }
         catch (Exception e)
         {
             throw new Exception(e.Message, e);
         }
         finally
         {
             dbcontext.Database.Connection.Close();
         }
     }
 }
Exemple #19
0
        public string InsertProfessor(int courseId, int profesorId)
        {
            using (CeLSDEntities dbcontext = new CeLSDEntities())
            {
                try
                {
                    CoursesUser coursesUser = new CoursesUser
                    {
                        CourseId = courseId,
                        UserId   = profesorId
                    };


                    var n = dbcontext.CoursesUsers.Add(coursesUser);
                    dbcontext.SaveChanges();
                    return("Success");
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e);
                }
            }
        }
Exemple #20
0
 public string Insert(string userName, string userEmail, string userPassword, int userType)
 {
     using (CeLSDEntities dbContext = new CeLSDEntities())
     {
         try
         {
             User user = new User()
             {
                 UserName     = userName,
                 UserEmail    = userEmail,
                 UserPassword = md5.GetMd5Sum(userPassword),
                 UserType     = userType
             };
             dbContext.Users.Add(user);
             dbContext.SaveChanges();
             return("Success");
         }
         catch (Exception exp)
         {
             throw new Exception(exp.Message, exp);
         }
     }
 }
Exemple #21
0
        public string Delete(int userId)
        {
            using (CeLSDEntities entity = new CeLSDEntities())
            {
                try
                {
                    entity.Database.Connection.Open();

                    User person = entity.Users.Single <User>(o => o.UserId == userId);
                    entity.Users.Remove(person);
                    entity.SaveChanges();

                    return("Success");
                }
                catch (Exception exp)
                {
                    throw new Exception(exp.Message, exp);
                }
                finally
                {
                    entity.Database.Connection.Close();
                }
            }
        }