Exemplo n.º 1
0
        public void Delete(string adminId)
        {
            var adminPersonId = courseAdminService.GetPersonId(adminId);

            // we cannot remove ourselves
            if (adminPersonId == httpContextAccessor.HttpContext.GetCurrentUserId())
            {
                throw new ApplicationException("Cannot remove own admin membership");
            }

            courseAdminService.RemoveById(adminId);
            courseAdminService.CommitChanges();
        }
        public void RemoveCurrentAdmin(string courseId)
        {
            string currentUserId = httpContextAccessor.HttpContext.GetCurrentUserId();
            var    currentAdmin  = courseAdminService.GetByUserAndCourse(currentUserId, courseId);

            var adminCount = courseService.GetAdminsWithUsers(courseId).Count;

            if (adminCount >= 2)
            {
                courseAdminService.RemoveById(currentAdmin.Id.ToString());
                courseAdminService.CommitChanges();
            }
            else
            {
                throw new ArgumentException("Cannot remove the last admin of the course.");
            }
        }