コード例 #1
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);
        }
コード例 #2
0
        public async Task <bool> DeleteQuestionAsync(long questionId, string userId)
        {
            var question = await _questionsRepository.GetById(questionId);

            var haveOwnerAccess = await _quizzesRepository.HaveOwnerAccessToQuiz(userId, question.QuizId);

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

            await _questionsRepository.SilentDelete(questionId, CurrentTime);

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