Esempio n. 1
0
        public IActionResult Questions(int id)
        {
            try
            {
                IEnumerable <Question> questions = questionManager.Find(x => x.PeriodId == id);

                return(Ok(questions));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to get answers for question {id}: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
Esempio n. 2
0
        public void Add_WhenQuestionIsValid_ReturnSuccess()
        {
            //Arrange
            //Act
            Question question = new Question {
                Title = "test", Body = _fixture.Create <string>(), Topic = _fixture.Create <string>().Substring(0, 5)
            };

            _mockRepository.Setup(m => m.Find(p => p.Title == "test")).Returns((Question)null).Verifiable();
            _mockRepository.Setup(m => m.Add(question)).Verifiable();
            _mockDal.Setup(m => m.Find(p => p.Title == "test")).Returns((Question)null).Verifiable();
            _mockDal.Setup(m => m.Add(new Question())).Verifiable();
            _service.Find(p => p.Title == "test");
            var result = _service.Add(question);

            //Assert
            // result.ShouldBe(new SuccessResult("Your Question successfully posted"));
            result.ShouldBeEquivalentTo(new SuccessResult("Your Question successfully posted"));
            _mockDal.Verify(m => m.Find(p => p.Title == "test"), Times.Once);
            _mockDal.Verify(m => m.Add(question), Times.Once);
        }
Esempio n. 3
0
        public IActionResult Search([FromQuery] Question question, [FromQuery] Period period,
                                    QuestionType questionType, [FromQuery] string isOpen, [FromQuery] string hasAnswers)
        {
            try
            {
                IEnumerable <Question> questions = questionManager.Find(x =>
                                                                        x.QuestionTypeId == question.QuestionTypeId &&
                                                                        x.PeriodId == question.PeriodId &&
                                                                        x.Period.StartDate == period.StartDate &&
                                                                        x.Period.EndDate == period.EndDate &&
                                                                        x.QuestionText == question.QuestionText &&
                                                                        x.QuestionSort == question.QuestionSort &&
                                                                        x.QuestionType.Description == questionType.Description);

                if (!string.IsNullOrWhiteSpace(isOpen))
                {
                    bool isOp;
                    bool.TryParse(isOpen, out isOp);

                    questions = questions.Where(x => x.Period.IsOpen == isOp);
                }

                if (!string.IsNullOrWhiteSpace(hasAnswers))
                {
                    bool hasAns;
                    bool.TryParse(hasAnswers, out hasAns);

                    questions = questions.Where(x => x.QuestionType.HasAnswers == hasAns);
                }

                return(Ok(questions));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to find question(s): {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
        public JsonResult AffixAnAnswer(string AnswerDescription, int questionid, int projectid, int askerId)
        {
            QuestionManager qm      = new QuestionManager();
            ProjectManager  pm      = new ProjectManager();
            Project         project = pm.Find(x => x.Id == projectid);

            Question            q   = qm.Find(x => x.Id == questionid);
            AnswerManager       anm = new AnswerManager();
            NotificationManager nm  = new NotificationManager();
            Notification        not = new Notification()
            {
                Type      = 4,
                ToWho     = askerId,
                projectid = projectid,
                Date      = DateTime.Now,
                Comment   = AnswerDescription,
                FromWho   = (Session["user"] as User).Id
            };

            Answer answer = new Answer()
            {
                AnswerDescription = AnswerDescription,
                question          = q,
                user = Session["user"] as User,
            };

            nm.Insert(not);

            int result = anm.Insert(answer);

            if (result > 0)
            {
                return(Json(new { isAdded = true, msg = "İşlem Başarılı" }));
            }
            return(Json(new { isAdded = false, msg = "Başarısız" }));
        }