示例#1
0
        public Response PostQuestion(QuestionModel question)
        {
            Response response = new Response();

            try
            {
                var id = Guid.NewGuid();
                response = _questionRepository.InsertQuestion(id, question);
                System.Console.WriteLine(response.IsSuccess);
                if (response.IsSuccess)
                {
                    var newTags          = question.Tags;                                                //get tagnames from the question
                    var existingTagNames = _tagRepository.GetTags(newTags).Select(x => x.Name).ToList(); //return tagnames of the existing tags
                    var addTags          = newTags.Except(existingTagNames).ToList();                    //get tagnames that doesnot exist in tag
                    var tagIds           = _tagManager.AddTags(addTags);                                 //add tags to tag and get tagids of new tags
                    response         = _questionRepository.AddQuestionTags(tagIds, id);                  //add tagids and questionid to the questiontag
                    response.Message = "Question and Tags Successfully Posted";                          //setting message in response
                }
                return(response);
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Message   = e.Message;

                return(response);
            }
        }