示例#1
0
        public async Task <ActionResult <QuestionGetSingleResponse> > PutQuestion(
            int questionId,
            QuestionPutRequest questionPutRequest)
        {
            var question = await _dataRepository.GetQuestion(questionId);

            if (question == null)
            {
                return(NotFound());
            }

            questionPutRequest.Title =
                string.IsNullOrEmpty(questionPutRequest.Title) ?
                question.Title :
                questionPutRequest.Title;
            questionPutRequest.Content =
                string.IsNullOrEmpty(questionPutRequest.Content) ?
                question.Content :
                questionPutRequest.Content;

            var savedQuestion =
                await _dataRepository.PutQuestion(
                    questionId,
                    questionPutRequest);

            _cache.Remove(savedQuestion.QuestionId);

            return(savedQuestion);
        }
示例#2
0
        public async Task <ActionResult <QuestionGetSingleResponse> > PutQuestion(int questionId, QuestionPutRequest questionPutRequest)
        {
            // TODO - get the question from the data repository
            var question = await _dataRepository.GetQuestion(questionId);

            // TODO - return HTTP status code 404 if the question isn't found
            if (question == null)
            {
                return(NotFound());
            }

            // TODO - update the question model
            questionPutRequest.Title =
                string.IsNullOrEmpty(questionPutRequest.Title)
                ? question.Title
                : questionPutRequest.Title;

            questionPutRequest.Content =
                string.IsNullOrEmpty(questionPutRequest.Content)
                ? question.Content
                : questionPutRequest.Content;

            // TODO - call the data repository with the updated question model to update the question in the database
            var savedQuestion = await _dataRepository.PutQuestion(questionId, questionPutRequest);

            // CACHE remove
            _cache.Remove(savedQuestion.QuestionId);

            // TODO - return the saved question
            return(savedQuestion);
        }
示例#3
0
        PutQuestion(int questionId,
                    QuestionPutRequest questionPutRequest)
        {
            // TODO - get the question from the data repository
            var question =
                _dataRepository.GetQuestion(questionId);

            // TODO - return HTTP status code 404 if the question isnt found
            if (question == null)
            {
                return(NotFound());
            }
            // TODO - update the question model
            questionPutRequest.Title =
                string.IsNullOrEmpty(questionPutRequest.Title) ?
                question.Title :
                questionPutRequest.Title;
            questionPutRequest.Content =
                string.IsNullOrEmpty(questionPutRequest.Content) ?
                question.Content :
                questionPutRequest.Content;
            // TODO - call the data repository with the updated question
            var savedQuestion =
                _dataRepository.PutQuestion(questionId,
                                            questionPutRequest);

            // TODO - remove from cache
            _cache.Remove(savedQuestion.QuestionId);
            // TODO - return the saved question
            return(savedQuestion);
        }
示例#4
0
        public async Task <ActionResult <QuestionGetSingleResponse> > PutQuestion(
            int questionId, QuestionPutRequest req)
        {
            var question = await _dataRepository.GetQuestion(questionId);

            if (question == null)
            {
                return(NotFound());
            }

            req.Title =
                string.IsNullOrEmpty(req.Title) ?
                question.Title :
                req.Title;

            req.Content =
                string.IsNullOrEmpty(req.Content) ?
                question.Content :
                req.Content;

            var putQuestion = await _dataRepository.PutQuestion(questionId, req);

            _cache.Remove(questionId);

            return(putQuestion);
        }