Beispiel #1
0
        public static IPostAnswerResult PostAnswer(PostAnswerCmd postAnswerCommand)
        {
            if (string.IsNullOrEmpty(postAnswerCommand.AnswerText))
            {
                var errors = new List <string>()
                {
                    "Invalid answer body"
                };
                return(new AnswerValidationFailed(errors));
            }

            var result = new PostAnswer(postAnswerCommand.AnswerText);

            return(result);
        }
        public ActionResult Tweet(PostInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var newPost = new Post {
                    Title   = model.Title, Content = model.Content,
                    PostURL = model.PostURL, UserID = this.UserProfile.Id, QuestionID = model.QuestionID
                };
                this.Data.Posts.Add(newPost);
                this.Data.SaveChanges();

                if (model.QuestionID != null)
                {
                    var newPostAnswer = new PostAnswer
                    {
                        ParentPostId = (int)model.QuestionID,
                        AnswerId     = newPost.Id
                    };

                    this.Data.PostAnswers.Add(newPostAnswer);
                    this.Data.SaveChanges();
                }

                if (this.HttpContext.Cache["allPosts"] != null)
                {
                    this.HttpContext.Cache.Remove("allPosts");
                }

                if (this.HttpContext.Cache[this.UserProfile.Id + "-Posts"] != null)
                {
                    this.HttpContext.Cache.Remove(this.UserProfile.Id + "-Posts");
                }

                this.TempData["Message"] = "Tweet created";
                return(this.RedirectToAction("Index", "Users", new { username = this.UserProfile.UserName }));
            }

            return(this.View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Post([FromBody] PostAnswer answers)
        {
            List <bool> values = answers.answers.ToList();

            if (values == null || values.Count <= 0)
            {
                return(BadRequest(new ErrorResponse(new DoughnutException("Parameter validation failed!!"))));
            }
            try
            {
                INode node = _decisionService.GetClildTree(values);
                if (node.LeafN == null && node.LeafY == null)
                {
                    //Return full tree with selected mark if all answer are given.
                    return(Ok(new SuccessResponse <dynamic>(new
                    {
                        //Statement = node.Statement,
                        Node = _decisionService.GetTraversedTree(answers.answers),
                        Answers = answers.answers
                    })));
                }
                return(Ok(new SuccessResponse <dynamic>(new
                {
                    Statement = node.Statement,
                    Answers = answers.answers
                })));
            }
            catch (NodeNotFoundException exception)
            {
                //Return Bad requers if invalid answer are given.
                return(BadRequest(new ErrorResponse(exception)));
            }
            catch (Exception ex) {
                //will change later.
                return(BadRequest(new ErrorResponse(new DoughnutException())));
            }
        }
Beispiel #4
0
 private static IPostAnswerResult ProcessAnswerPosted(PostAnswer answer)
 {
     Console.WriteLine($"Answer: {answer.AnswerText}");
     return(answer);
 }