Beispiel #1
0
        public async Task <DeleteQuizResponseDTO> DeleteQuizAsync(DeleteQuizRequestDTO deleteRequest)
        {
            var result = new DeleteQuizResponseDTO
            {
                Request = deleteRequest
            };

            var quiz = await _quizRepo.GetQuizAsync(deleteRequest.QuizId);

            if (quiz == null)
            {
                result._result = DeleteQuizResponseDTO.RequestResult.QuizNotFound;
                return(result);
            }

            if (quiz.Owner.Id != deleteRequest.CharacterId)
            {
                result._result = DeleteQuizResponseDTO.RequestResult.CharacterNotOwner;
                return(result);
            }

            await _quizRepo.DeleteQuizAsync(quiz);

            try
            {
                await _quizRepo.SaveChangesAsync();

                result._result = DeleteQuizResponseDTO.RequestResult.Success;
            }catch (Exception)
            {
                result._result = DeleteQuizResponseDTO.RequestResult.BadRequest;
            }

            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteQuiz(DeleteQuizRequestDTO deleteRequest)
        {
            var result = await _quizService.DeleteQuizAsync(deleteRequest);

            switch (result._result)
            {
            case DeleteQuizResponseDTO.RequestResult.Success: return(Ok(result));

            case DeleteQuizResponseDTO.RequestResult.QuizNotFound: return(NotFound(result));

            default: return(BadRequest(result));
            }
        }