Beispiel #1
0
        public async Task <CourseAccess> GrantAccessAsync(string courseId, string userId, CourseAccessType accessType, string grantedById, string comment)
        {
            courseId = courseId.ToLower();
            var currentAccess = new CourseAccess
            {
                CourseId    = courseId,
                UserId      = userId,
                AccessType  = accessType,
                GrantTime   = DateTime.Now,
                GrantedById = grantedById,
                IsEnabled   = true,
                Comment     = comment
            };

            db.CourseAccesses.Add(currentAccess);

            await db.SaveChangesAsync().ConfigureAwait(false);

            return(db.CourseAccesses.Include(a => a.GrantedBy).Single(a => a.Id == currentAccess.Id));
        }
Beispiel #2
0
        /* Course accesses */

        public async Task <CourseAccess> GrantAccess(string courseId, string userId, CourseAccessType accessType, string grantedById)
        {
            var currentAccess = db.CourseAccesses.FirstOrDefault(a => a.CourseId == courseId && a.UserId == userId && a.AccessType == accessType);

            if (currentAccess == null)
            {
                currentAccess = new CourseAccess
                {
                    CourseId   = courseId,
                    UserId     = userId,
                    AccessType = accessType,
                };
                db.CourseAccesses.Add(currentAccess);
            }
            currentAccess.GrantedById = grantedById;
            currentAccess.GrantTime   = DateTime.Now;
            currentAccess.IsEnabled   = true;

            await db.SaveChangesAsync();

            return(db.CourseAccesses.Include(a => a.GrantedBy).Single(a => a.Id == currentAccess.Id));
        }
Beispiel #3
0
        public async Task <List <CourseAccess> > RevokeAccessAsync(string courseId, string userId, CourseAccessType accessType, string grantedById, string comment)
        {
            courseId = courseId.ToLower();
            var revoke = new CourseAccess
            {
                UserId      = userId,
                GrantTime   = DateTime.Now,
                GrantedById = grantedById,
                Comment     = comment,
                IsEnabled   = false,
                CourseId    = courseId,
                AccessType  = accessType
            };

            db.CourseAccesses.Add(revoke);

            await db.SaveChangesAsync();

            return(new List <CourseAccess> {
                revoke
            });
        }
 public CoursesController(CourseAccess courses)
 {
     Courses = courses;
 }