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); } }
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()); } } }
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()); } } }
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); } } }