示例#1
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);
            }
        }
示例#2
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());
         }
     }
 }
示例#3
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());
         }
     }
 }
示例#4
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);
                }
            }
        }