示例#1
0
        static void CheckExceptions(IRedisResults result)
        {
            var error = result[0].GetException();

            if (error != null)
            {
                switch (error.Prefix)
                {
                case "ALREADYVOTED": throw new SimpleQAException("User already voted");

                default: throw error;
                }
            }
        }
示例#2
0
        static void CheckException(IRedisResults result)
        {
            var error = result[0].GetException();

            if (error != null)
            {
                switch (error.Prefix)
                {
                case "NOTFOUND":
                    throw new SimpleQAException("Question not found");

                default: throw error;
                }
            }
        }
        static void CheckException(IRedisResults result)
        {
            var error = result[0].GetException();

            if (error != null)
            {
                switch (error.Prefix)
                {
                case "NOTOWNER":
                    throw new SimpleQAException("You are not the author of the answer you try to edit.");

                default:
                    throw error;
                }
            }
        }
示例#4
0
        static void CheckException(IRedisResults result)
        {
            var error = result[0].GetException();

            if (error != null)
            {
                switch (error.Prefix)
                {
                case "NOTOWNER":
                    throw new SimpleQANotOwnerException("You cannot close a question that is yours.");

                case "CANNOTCLOSE":
                    throw new SimpleQANotOwnerException("Tne question is not open anymore.");

                default: throw error;
                }
            }
        }
示例#5
0
        private static List <AnswerViewModel> ExtractAnswers(SimpleQAIdentity user, IRedisResults results, QuestionViewModel question)
        {
            var answers = new List <AnswerViewModel>();

            foreach (var answerData in results)
            {
                var answerResult = answerData.AsResults();

                var answer = new AnswerViewModel();
                answerResult[0].AsObjectCollation(answer);
                answer.User           = answerResult[1].GetString();
                answer.QuestionId     = question.Id;
                answer.Editable       = question.Status == QuestionStatus.Open;
                answer.Votable        = question.Votable;
                answer.AuthoredByUser = answer.User == user.Name;
                answer.UpVoted        = GetVote(answerResult[2].GetString());
                answers.Add(answer);
            }
            return(answers);
        }