예제 #1
0
        public void AddUserToCourse(string userId, int courseId)
        {
            CourseUsers courseUsers = new CourseUsers
            {
                CourseId  = courseId,
                AppUserId = userId,
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };

            context.CourseUsers.Add(courseUsers);
            context.SaveChanges();

            //add notification
            NewNotification(userId, "UserJoinCourse", "Course", courseId);
        }
예제 #2
0
        public void DeleteUserFromCourse(string userId, int courseId)
        {
            CourseUsers dbEntry = context.CourseUsers
                                  .FirstOrDefault(cu => cu.AppUserId == userId &&
                                                  cu.CourseId == courseId);

            if (dbEntry != null)
            {
                Course course = context.Courses
                                .FirstOrDefault(c => c.CourseId == courseId);
                foreach (Presentation p in course.Presentations)
                {
                    Representation deleteRep = p.Representations
                                               .FirstOrDefault(r => r.CreatedBy.Id == userId);
                    DeleteRepresentation(deleteRep.RepresentationId);
                }
                context.CourseUsers.Remove(dbEntry);
                context.SaveChanges();
            }
        }