Exemplo n.º 1
0
        public IActionResult Index(int id)
        {
            var post = _postService.TakeById(id);

            var postReplies = TakePostReplies(post.PostReplies);

            var viewModel = new IndexPostModel
            {
                Id              = post.Id,
                Title           = post.Title,
                ForumId         = post.Forum.Id,
                ForumTitle      = post.Forum.Title,
                CreatedOn       = post.CreatedOn,
                AuthorName      = post.User.UserName,
                AuthorId        = post.User.Id,
                Content         = post.Content,
                IsAdministrator = IsAdministrator(post.User),
                AuthorRating    = post.User.Rating,
                AuthorPicture   = post.User.ProfilePic,
                Replies         = postReplies
            };


            return(View(viewModel));
        }
        public IActionResult Index(IndexPostModel model)
        {
            if (!model.DateOfBirthIsValid())
            {
                ModelState.AddModelError("DateOfBirth", "Please enter a valid date of birth");
            }

            if (!ModelState.IsValid)
            {
                return(Index());
            }

            var querier = new RecommendedCardsQuerier(_dateTime);
            var results = querier.Query(model.GetDateOfBirth(), model.AnnualIncome.Value);

            _logHandler.Handle(new LogCustomerApplication
            {
                FirstName        = model.FirstName,
                LastName         = model.LastName,
                DateOfBirth      = model.GetDateOfBirth(),
                AnnualIncome     = model.AnnualIncome.Value,
                RecommendedCards = results.Select(r => r.Name).ToArray()
            });

            return(View("Recommendations", results));
        }
        public void ShouldLogCustomerApplication()
        {
            using (var db = new FakeDbContext())
            {
                var dateTime         = new FakeDateTimeService(new DateTime(2020, 2, 8));
                var ipAddressService = new FakeClientIpAddressService("192.168.0.1");
                var handler          = new LogCustomerApplicationHandler(db, dateTime, ipAddressService);

                var sut = new HomeController(dateTime, handler);

                var model = new IndexPostModel
                {
                    FirstName    = "Joe",
                    LastName     = "Bloggs",
                    BirthDay     = 1,
                    BirthMonth   = 1,
                    BirthYear    = 1980,
                    AnnualIncome = 30000
                };

                sut.Index(model);

                var applications = db.CustomerApplications.ToArray();

                Assert.Single(applications);

                var first = applications.First();

                Assert.Equal(model.FirstName, first.FirstName);
                Assert.Equal(model.LastName, first.LastName);
                Assert.Equal(model.GetDateOfBirth(), first.DateOfBirth);
                Assert.Equal(model.AnnualIncome, first.AnnualIncome);
                Assert.Equal(dateTime.Now, first.CreatedDate);
                Assert.Equal("192.168.0.1", first.IpAddress);
            }
        }