Exemplo n.º 1
0
        static CreateQuestionResult.IAskQuestionResult AskQuestion(CreateQuestionCmd cmd)
        {
            if (string.IsNullOrWhiteSpace(cmd.Title))
            {
                string error = new string ("Title is empty! But it hasn't had to be...");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }

            if (string.IsNullOrWhiteSpace(cmd.Text))
            {
                string error = new string ("Body is empty but it hasn't had to be...!");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }

            if (new Random().Next(10) > 7) //simulare analiza text
            {
                var error = new List <string> {
                    " validation failed!"
                };
                return(new CreateQuestionResult.QuestionValidationFailed(error));
            }

            var Id     = Guid.NewGuid();
            var result = new CreateQuestionResult.QuestionAdded(Id, cmd.Title, cmd.Text, cmd.Tags);

            return(result);
        }
Exemplo n.º 2
0
        static CreateQuestionResult.IAskQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                string error = new string ("Title is empty!But it hasn't had to be");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Text))
            {
                string error = new string ("Body is empty!But it hasn't had to be");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }

            if (new Random().Next(10) > 7)
            {
                var error = new List <string> {
                    "Validation Failed"
                };
                return(new CreateQuestionResult.QuestionValidationFailed(error));
            }


            var Id     = Guid.NewGuid();
            var result = new CreateQuestionResult.QuestionAdded(Id, createQuestionCommand.Title, createQuestionCommand.Text, createQuestionCommand.Tags);

            return(result);
        }
Exemplo n.º 3
0
        private static string ProcessQuestionCreated(CreateQuestionResult.QuestionAdded createQuestionResult)
        {
            Console.WriteLine("Id:" + createQuestionResult.Id);
            Console.WriteLine("Title: " + createQuestionResult.Title);
            Console.WriteLine("Body: " + createQuestionResult.Text);
            Console.WriteLine("Tags:");
            foreach (var item in createQuestionResult.Tags)
            {
                Console.WriteLine(item);
            }

            return(createQuestionResult.ToString());
        }
Exemplo n.º 4
0
        static CreateQuestionResult.IAskQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                string error = new string("Title is empty!But it hasn't had to be");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }
            if (createQuestionCommand.Title.Length < 0 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    " title must have more than 8 characters"
                };
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (createQuestionCommand.Title.Length > 1000)
            {
                var errors = new List <string>()("Tile mustn't  be longer than 180 caracters");
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Text))
            {
                string error = new string("Body is empty!But it hasn't had to be");
                return(new CreateQuestionResult.QuestionNotAdded(error));
            }

            if (createQuestionCommand.Text.Length < 0 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()("Body must have more than 10 characters");
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (createQuestionCommand.Text.Length > 1000)
            {
                var errors = new List <string>()("Body must have just 1000 characters");
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (createQuestionCommand.Tags.Length < 1)
            {
                var errors = new List <string>()("Enter one tags");
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (createQuestionCommand.Tags.Lenght > 3)
            {
                var errors = new List <string>()("You entered too much tags,please delete some of them to have just 3");
                return(new CreateQuestionResult.QuestionNotAdded(errors));
            }

            if (new Random().Next(10) > 7)
            {
                var error = new List <string> {
                    "Validation Failed"
                };
                return(new CreateQuestionResult.QuestionValidationFailed(error));
            }


            var Id     = Guid.NewGuid();
            var result = new CreateQuestionResult.QuestionAdded(Id, createQuestionCommand.Title, createQuestionCommand.Text, createQuestionCommand.Tags);

            return(result);
        }