Ejemplo n.º 1
0
        public static PostNewQuestionResult PostNewQuestion(NewQuestionCmd newQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(newQuestionCommand.Title))
            {
                //var errors = new List<string>() { "Title can not pe NULL!" };
                return(new QuestionNotPosted("Title can not pe NULL!"));
            }
            if (string.IsNullOrWhiteSpace(newQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invalid Body! Body can not be NULL!"
                };
                return(new QuestionValidationFailed(errors));
            }



            var questId = Guid.NewGuid();
            var result  = new QuestionPosted(questId, newQuestionCommand.Title, newQuestionCommand.Body, newQuestionCommand.Tags);


            //execute logic
            return(result);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var cmd    = new NewQuestionCmd("Numele user-ului", "Titlu", "Descrierea intrebarii", "Domeniul din care este intrebarea / tag-ul");
            var result = NewQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var cmd = new NewQuestionCmd("How can I remove a specific item from an array?", "I have an array of numbers and I'm using the .push() method to add elements to it.Is there a simple way to remove a specific element from an array?I'm looking for the equivalent of something like: array.remove(number); I have to use core JavaScript. Frameworks are not allowed.", "javascript, arrays");
            //exemplu verificare titlu null
            //var cmd = new NewQuestionCmd("", "I have an array of numbers and I'm using the .push() method to add elements to it.Is there a simple way to remove a specific element from an array?I'm looking for the equivalent of something like: array.remove(number); I have to use core JavaScript. Frameworks are not allowed.", "javascript, arrays");

            var result = PostNewQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public static INewQuestionResult NewQuestion(NewQuestionCmd newQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(newQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Please provide a title"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (string.IsNullOrWhiteSpace(newQuestionCommand.Description))
            {
                var errors = new List <string>()
                {
                    "Please provide a description for the question"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (string.IsNullOrWhiteSpace(newQuestionCommand.DomainTag))
            {
                var errors = new List <string>()
                {
                    "Please provide a domain/tag for the question"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotPosted("ML validation failed"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionPosted(questionId, newQuestionCommand.UserName);

            //execute logic
            return(result);
        }