public ActionResult Create(QuizAccess quiz)
        {
            QuizTransfer quizModule = new QuizTransfer();
            QuizAccess   quizDe     = new QuizAccess();

            try
            {
                if (Request.Form.Get("moduleId") != null)
                {
                    quiz.ModuleId = Convert.ToInt32(Request.Form.Get("moduleId"));
                }
                quizDe = quiz;
                quizModule.QuizDescription = quizDe;
                Session.Add("quiz", quizModule);
                return(RedirectToAction("question"));
            }
            catch (Exception ex)
            {
                //get the innermost exception
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                ModelState.AddModelError("", "error on insert: " + ex.GetBaseException().Message);
                return(View());
            }
        }
Beispiel #2
0
        public async Task <bool> AddAccess(Guid quizId, string userId)
        {
            var isPublic = await _quizzesRepository.IsPublicAsync(quizId);

            if (!isPublic)
            {
                return(false);
            }

            var access = new QuizAccess {
                UserId = userId,
                QuizId = quizId,
                Access = QuizAccessEnum.Solver
            };
            await _quizAccessesRepository.CreateOrUpdate(access);

            return(await Context.SaveChangesAsync() > 0);
        }
Beispiel #3
0
        public async Task <bool> GiveAccess(Guid quizId, string userId, string email, QuizAccessEnum accessType)
        {
            if (accessType == QuizAccessEnum.Solver)
            {
                var haveWriteAccess = await _quizzesRepository.HaveWriteAccessToQuiz(userId, quizId);

                if (!haveWriteAccess)
                {
                    return(false);
                }
            }
            else
            {
                var haveOwnerAccess = await _quizzesRepository.HaveOwnerAccessToQuiz(userId, quizId);

                if (!haveOwnerAccess)
                {
                    return(false);
                }
            }

            var users = await _auth0UsersService.GetUsersByEmailAsync(email);

            if (users == null || users.Count == 0)
            {
                return(false);
            }

            foreach (var user in users)
            {
                var access = new QuizAccess {
                    Access = accessType,
                    QuizId = quizId,
                    UserId = user.UserId
                };
                await _quizAccessesRepository.CreateOrUpdate(access);
            }

            return(await Context.SaveChangesAsync() > 0);
        }