예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 public QuestionGetSingleResponse PutQuestion(int questionId, QuestionPutRequest question)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         connection.Execute(@"EXEC dbo.Question_Put @QuestionId = @QuestionId, @Title = @Title, @Content = @Content", new { QuestionId = questionId, question.Title, question.Content });
         return(GetQuestion(questionId));
     }
 }
예제 #5
0
        public async Task <QuestionGetSingleResponse> PutQuestion(int questionId, QuestionPutRequest question)
        {
            using (var connection = new SqlConnection(_connectionString)) {
                await connection.OpenAsync();

                await connection.ExecuteAsync(@"EXEC dbo.Question_Put 
                    @QuestionId = @QuestionId, @Title = @Title, @Content = @Content",
                                              new { QuestionId = questionId, question.Title, question.Content });

                return(await GetQuestion(questionId));
            }
        }
        public ActionResult <QuestionGetSingleResponse> PutQuestion(int questionId, [FromBody] QuestionPutRequest questionPut)
        {
            var question = _dataRepository.GetQuestion(questionId);

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

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

            var savedQuestion = _dataRepository.PutQuestion(questionId, questionPut);

            return(savedQuestion);
        }
예제 #7
0
        public ActionResult <QuestionGetSingleResponse> PutQuestion(int questionId, QuestionPutRequest questionPutRequest)
        {
            var question = _dataRepository.GetQuestion(questionId);

            if (question == null)
            {
                return(NotFound());
            }
            //using ternary expressions to update the request model with dataa from the existing question if it hasn't been supplied in the request
            questionPutRequest.Title   = string.IsNullOrEmpty(questionPutRequest.Title) ? question.Title : questionPutRequest.Title;
            questionPutRequest.Content = string.IsNullOrEmpty(questionPutRequest.Content) ? question.Content : questionPutRequest.Content;

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

            return(savedQuestion);
        }
        PutQuestion(int questionId, QuestionPutRequest questionPutRequest)
        {
            var question = _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 = _dataRepository.PutQuestion(questionId, questionPutRequest);

            return(savedQuestion);
        }
예제 #9
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);
        }