Пример #1
0
        public ActionResult LawDetails(int?lawId, string pCode, string scrollPosition, string sp)
        {
            if (lawId == null)
            {
                return(HttpNotFound());
            }

            LawService service = new LawService();
            LawModel   model   = service.GetLawModel(lawId.Value, User.Identity.GetUserId(), Infrastructure.CommentOrder.Chronological);

            if (model == null)
            {
                return(HttpNotFound());
            }

            new ParliamentService().GetTenantData(model.Law.ParliamentID, out string parliamentCode);
            if (pCode == null || pCode != parliamentCode)
            {
                return(RedirectToRoute(JavnaRasprava.Resources.Routes.JavnaRasprava_LawDetails, new { pCode = parliamentCode, lawId }));
            }

            QuestionsService questionsService = new QuestionsService();

            model.RepresentativeAnswers = questionsService.GetLatestAnswersForLaw(lawId.Value, User.Identity.GetUserId());

            ViewBag.scrollPosition = sp ?? scrollPosition;

            model.FbCommentsPath = string.Format(ConfigurationManager.AppSettings["Facebook.LawUrlTemplate"], lawId);

            return(View("Law", model));
        }
Пример #2
0
        public void GetLatestAnswers_ChainMethods()
        {
            ApplicationDbContext context = null;
            var law = Helpers.CreateLaw(1, new List <string> {
                "AmirFazlic", "AsimSarajlic", "SalkoSokolovic"
            }, new List <string> {
                "First Question", "Second Question"
            });
            var user1 = Helpers.CreateNewUser();

            try
            {
                var service = new QuestionsService();

                var askmodel1 = service.GetQuestionsModel(law.LawID, user1.Id);
                askmodel1.SuggestedRepresentatives[0].IsSelected = true;
                askmodel1.SuggestedRepresentatives[1].IsSelected = true;
                askmodel1.SuggestedRepresentatives[2].IsSelected = true;
                askmodel1.Questions[0].IsSelected = true;
                askmodel1.Questions[1].IsSelected = true;

                service.PostQuestion(askmodel1, user1.Id);



                context = ApplicationDbContext.Create();

                context.Answers.AddRange(new List <Answer>
                {
                    new Answer {
                        QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[0].ID, Text = "Test answer 00", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(1)
                    },

                    new Answer {
                        QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[1].ID, Text = "Test answer 01", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(2)
                    },
                    new Answer {
                        QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[2].ID, Text = "Test answer 02", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(3)
                    },
                    new Answer {
                        QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[0].ID, Text = "Test answer 10", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(4)
                    },
                    new Answer {
                        QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[1].ID, Text = "Test answer 11", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(5)
                    },
                    new Answer {
                        QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[2].ID, Text = "Test answer 12", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(6)
                    },
                });
                context.SaveChanges();

                var response = service.GetLatestAnswersForLaw(law.LawID, user1.Id, 5);

                Assert.AreEqual(law.LawID, response.LawID, "Law ID");
                Assert.AreEqual(5, response.Count, "Total question count");
                Assert.IsNotNull(response.Answers, "Answers returned");
                Assert.IsNotNull(response.Answers[0].Question, "Question populated");
                Assert.IsNotNull(response.Answers[0].Representative, "Representative populated");

                var selectedAnswer = response.Answers.Where(x => x.Question.Id == askmodel1.Questions[0].ID && x.Representative.ID == askmodel1.SuggestedRepresentatives[2].ID).First();

                Assert.AreEqual("Test answer 02", selectedAnswer.Text);
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }

                Helpers.DeleteLaw(law);
                Helpers.DeleteUser(user1);
            }
        }