Example #1
0
        public QuestionCreated VoteUp1(QuestionCreated question, VoteEnum vote)
        {
            var vot = question.Vot;

            vot.Append(vote);
            return(new QuestionCreated(question.QuefileTi, question.Question, vot.Sum(v => Convert.ToInt32(v)), vot));
        }
Example #2
0
        public QuestionCreated Votes(QuestionCreated question, Vote vote)
        {
            var totalVotes = question.TotalVotes;

            totalVotes.Append(vote);
            return(new QuestionCreated(question.QuestionId, question.Body, totalVotes.Sum(v => Convert.ToInt32(v)), totalVotes));
        }
Example #3
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            bool isMLApproved = true;

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Invalid title"
                };
                return(new QuestionValidationFailed(errors));
            }
            else if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invalid body"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (new Random().Next(5) > 1)
            {
                isMLApproved = false;
                return(new QuestionNotCreated("Question is not approved"));
            }
            var questionId = Guid.NewGuid();
            var results    = new QuestionCreated(questionId, createQuestionCommand.Title, "*****@*****.**", isMLApproved);

            return(results);
        }
Example #4
0
        public QuestionCreated Update(QuestionCreated result, VoteCountEnum vote) 
        {
            var allVotes = result.allVotes.ToList();
            allVotes.Add(vote);

            return new QuestionCreated(result.Id, result.Title, result.Content, result.Tag, allVotes.Sum(nVotes => Convert.ToInt32(nVotes)), allVotes);
    }
Example #5
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Invlaid title"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invlaid text"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Text could not be verified"));
            }

            var questionId = Guid.NewGuid();
            var result2    = new QuestionCreated(questionId, createQuestionCommand.Title);

            //execute logic

            return(result2);
        }
Example #6
0
        public QuestionCreated Update(QuestionCreated question, Vote vote)
        {
            var votes = question.AllVotes;

            votes.Append(vote);

            return(new QuestionCreated(question.QuestionId, question.Title, question.Description, question.Tags, votes.Sum(v => Convert.ToInt32(v)), votes));
        }
        public void Apply(QuestionCreated questionCreated)
        {
            var question = questionCreated.Question;

            if (question.Length > 100)
            {
                question = question.Substring(0, 100);
            }
            Questions = question;
        }
Example #8
0
        public static ICreateQuestionResult QuestionCreated(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Invlaid Title"
                };
                return(new QuestionValidationFailed(errors));
            }

            var result = new QuestionCreated(quefileTi, createQuestionCommand.Title);

            //execute logic
            return(result);
        }
        public static ICreatedQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title) || string.IsNullOrWhiteSpace(createQuestionCommand(Description)))
            {
                var errors = new List <string>()
                {
                    "Invalid title or description"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Question could not be verified"));
            }
            var questionId = Guid.NewGuid();
            var results    = new QuestionCreated(questionId, createQuestionCommand.Title, createQuestionCommand.Description);

            return(results);
        }
        public static ICreatedQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title) || string.IsNullOrWhiteSpace(createQuestionCommand(Description)))
            {
                var errors = new List <string>()
                {
                    "Titlu sau descriere invalida"
                };
                return(new QuestionValidationFailed(errors));
            }
            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Intrebarea nu a putut fi validata"));
            }
            var questionId = Guid.NewGuid();
            var results    = new QuestionCreated(questionId, createQuestionCommand.Title, createQuestionCommand.Description);

            return(results);
        }
Example #11
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invalid body content"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Body content could not be verified"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionCreated(questionId, createQuestionCommand.Body);

            return(result);
        }
Example #12
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Title is missing"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length < 15 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Title cannot be shorter than 15 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length > 150)
            {
                var errors = new List <string>()
                {
                    "Title cannot be longer than 150 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Body is missing"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length < 30 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Body cannot be shorter than 30 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length > 30000)
            {
                var errors = new List <string>()
                {
                    "Body is limited to 30000 characters; you entered 100124."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Tags.Length < 1)
            {
                var errors = new List <string>()
                {
                    "Please enter at least one tag; see a list of popular tags."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Question could not be verified"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionCreated(questionId, createQuestionCommand.Title, "*****@*****.**", true);

            if (result.MLApproved)
            {
                result.SetQuestionProfileCount();
                Console.WriteLine(result.QuestionProfileNumber);
            }
            else
            {
                Console.WriteLine(result.QuestionProfileNumber);
                QuestionNotCreated feedback = new QuestionNotCreated("Question closed. Please edit it or delete it.");
            }

            //execute logic
            return(result);
        }
Example #13
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Titlu lipsa"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length < 10 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Titlul nu poate sa contina mai putin de 10 caractere."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length > 180)
            {
                var errors = new List <string>()
                {
                    "Titlul nu poate avea mai mult de 200 de caractere."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Continut lipsa"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length < 15 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Continutul nu poate avea mai putin de 15 caractere."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length > 10000)
            {
                var errors = new List <string>()
                {
                    "Continutul nu poate avea mai mult de 1000 caractere. Ati introdus 1001 caractere"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Tags.Length < 1)
            {
                var errors = new List <string>()
                {
                    "Introduceti cel putin un tag"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Tags.Length > 10)
            {
                var errors = new List <string>()
                {
                    "Ati introdus prea multe taguri"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Intrebarea nu s-a putut valida"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionCreated(questionId, createQuestionCommand.Title, "*****@*****.**", true);

            if (result.form)
            {
                Console.WriteLine(result.ToString());
            }
            else
            {
                QuestionNotCreated feedback = new QuestionNotCreated("Intrebarea nu s-a creat !");
            }

            return(result);
        }
Example #14
0
 private static ICreateQuestionResult ProcessQuestionCreated(QuestionCreated quefileTi)
 {
     Console.WriteLine($"Question {quefileTi.QuefileTi}");
     return(quefileTi);
 }
Example #15
0
 private static ICreateQuestionResult ProcessQuestionCreated(QuestionCreated question)
 {
     Console.WriteLine($"Question {question.QuestionId}");
     return(question);
 }
Example #16
0
 public void Apply(QuestionCreated questionCreated)
 {
     Question = questionCreated.Question;
 }
Example #17
0
 //Later change QuestionCreated to IEvent to handle many events :)
 static Task Apply(Metadata meta, QuestionCreated questionCreated, QuestionTeasersWith100CharactersState questionTeasersWith100Characters)
 {
     questionTeasersWith100Characters.Apply(questionCreated);
     return(Task.CompletedTask);
 }
Example #18
0
        public static ICreateQuestionResult CreateQuestion(CreateQuestionCmd createQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Title is missing"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length < 8 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Title cannot be shorter than 8 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Title.Length > 180)
            {
                var errors = new List <string>()
                {
                    "Title cannot be longer than 180 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (string.IsNullOrWhiteSpace(createQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Body is missing"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length < 10 && !string.IsNullOrWhiteSpace(createQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Body cannot be shorter than 10 characters."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Body.Length > 10000)
            {
                var errors = new List <string>()
                {
                    "Body is limited to 10000 characters; you entered 10005."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Tags.Length < 1)
            {
                var errors = new List <string>()
                {
                    "Please enter at least one tag; see a list of popular tags."
                };
                return(new QuestionValidationFailed(errors));
            }

            if (createQuestionCommand.Tags.Length > 8)
            {
                var errors = new List <string>()
                {
                    "You entered to much tags, you need to delete some of these"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotCreated("Question could not be verified"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionCreated(questionId, createQuestionCommand.Title, "*****@*****.**", true);

            if (result.form)
            {
                Console.WriteLine(result.ToString());
            }
            else
            {
                QuestionNotCreated feedback = new QuestionNotCreated("Question was closed, can be created !");
            }

            return(result);
        }
 private Task Apply(Metadata metadata, QuestionCreated questionCreated, QuestionWithAnswersState state)
 {
     state.Apply(questionCreated);
     return(Task.CompletedTask);
 }