예제 #1
0
        public void StoreQuestion(Question question)
        {
            using (var redis = RedisManager.GetClient())
            {
                var redisQuestions = redis.As<Question>();

                if (question.Tags == null) question.Tags = new List<string>();
                if (question.Id == default(long))
                {
                    question.Id = redisQuestions.GetNextSequence();
                    question.CreatedDate = DateTime.UtcNow;

                    //Increment the popularity for each new question tag
                    question.Tags.ForEach(tag => redis.IncrementItemInSortedSet(TagIndex.All, tag, 1));
                }

                redisQuestions.Store(question);
                redisQuestions.AddToRecentsList(question);
                redis.AddItemToSet(UserQuestionIndex.Questions(question.UserId), question.Id.ToString());

                //Populate tag => questions index for each tag
                question.Tags.ForEach(tag => redis.AddItemToSet(TagIndex.Questions(tag), question.Id.ToString()));
            }
        }
 public void Post(Question question)
 {
     Repository.StoreQuestion(question);
 }
 public void Delete(Question request)
 {
     Repository.DeleteQuestion(request.Id);
 }
 public object Get(Question question)
 {
     return new QuestionResponse {
         Result = Repository.GetQuestion(question.Id),
     };
 }