Exemplo n.º 1
0
        private async Task <JsonResult> NotifyClientsAndGenerateVoteResultAsync(long countdownId, int currentUserAccountId)
        {
            CountdownAggregate countdownAggregate = await _countdownRepository.GetAggregateAsync(countdownId, currentUserAccountId);

            await _notificationService.ClearCountdownVoteNotificationsAsync(countdownId, countdownAggregate.CreatedByAccountId, currentUserAccountId);

            if (countdownAggregate.CurrentUserVote != 0)
            {
                var notificationChange = new NotificationChange {
                    CreatedByAccountId     = currentUserAccountId,
                    CreatedOn              = _systemClock.UtcNow,
                    NotificationActionType = countdownAggregate.CurrentUserVote > 0 ? NotificationActionType.Upvoted : NotificationActionType.Downvoted
                };
                await _notificationService.NotifyCountdownOwnerAsync(countdownId, notificationChange);
            }

            _notificationService.UpdateClientsAfterVote(countdownAggregate);

            var model = new CountdownVoteViewModel {
                CountdownId     = countdownId,
                VoteScore       = countdownAggregate.VoteScore,
                CurrentUserVote = countdownAggregate.CurrentUserVote
            };

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Details(long countdownId)
        {
            CountdownAggregate countdown = await _countdownRepository.GetAggregateAsync(countdownId, _contextService.CurrentUserAccountId);

            if (countdown == null)
            {
                return(new HttpStatusCodeResult(404, "Not Found"));
            }

            CountdownViewModel model = countdown.ToCountdownViewModel();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public async Task GetWithCountdownId_ReturnsCountdownAggregate()
        {
            TestableCountdownController controller = TestableCountdownController.Create();
            const long countdownId        = 1;
            var        countdownAggregate = new CountdownAggregate {
                Id                   = countdownId,
                CreatedOn            = DateTime.UtcNow,
                Description          = "test description",
                EndsOn               = DateTime.UtcNow.AddYears(1),
                CreatedByAccountId   = 1,
                CommentsCount        = 37,
                CreatedByDisplayName = "testo",
                CurrentUserVote      = -1,
                VoteScore            = 71
            };

            controller.CountdownRepository.CountdownAggregates.Add(countdownAggregate);

            JsonResult result = await controller.Details(countdownId) as JsonResult;

            Assert.IsNotNull(result);

            CountdownViewModel countdownViewModel = result.Data as CountdownViewModel;

            Assert.IsNotNull(countdownViewModel);
            Assert.AreEqual(countdownAggregate.Id, countdownViewModel.Id);
            Assert.AreEqual(countdownAggregate.CreatedOn, countdownViewModel.CreatedOn);
            Assert.AreEqual(countdownAggregate.Description, countdownViewModel.Description);
            Assert.AreEqual(countdownAggregate.EndsOn, countdownViewModel.EndsOn);
            Assert.AreEqual(countdownAggregate.CreatedByAccountId, countdownViewModel.CreatedByAccountId);
            Assert.AreEqual(countdownAggregate.CommentsCount, countdownViewModel.CommentsCount);
            Assert.AreEqual(countdownAggregate.CreatedByDisplayName, countdownViewModel.CreatedByDisplayName);
            Assert.AreEqual(countdownAggregate.CurrentUserVote, countdownViewModel.CurrentUserVote);
            Assert.AreEqual(countdownAggregate.VoteScore, countdownViewModel.VoteScore);
            Assert.IsNotNull(countdownViewModel.CreatedByGravatarUrl);
        }
Exemplo n.º 4
0
 public void UpdateClientsAfterVote(CountdownAggregate countdownAggregate)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 5
0
 public void BroadcastCountdownUpdate(CountdownAggregate countdownAggregate) => Hub.Clients.All.broadcastCountdownUpdate(countdownAggregate);
Exemplo n.º 6
0
 public static CountdownViewModel ToCountdownViewModel(this CountdownAggregate countdownAggregate)
 {
     return(Mapper.Map <CountdownAggregate, CountdownViewModel>(countdownAggregate));
 }
Exemplo n.º 7
0
 public void UpdateClientsAfterVote(CountdownAggregate countdownAggregate) => _notificationHub.BroadcastCountdownUpdate(countdownAggregate);