Beispiel #1
0
        public ActionResult <Invitation> AcceptInvitation(string id)
        {
            Invitation invitation = _invitationService.GetFromInvitationId(id);

            if (invitation == null)
            {
                return(StatusCode(404, "Invitation non trouvee"));
            }
            if (invitation.Status != 0)
            {
                return(StatusCode(400, "Impossible d'accepter l'invitation car elle n'est pas en attente."));
            }
            var res  = _invitationService.AcceptInvitation(id);
            var user = _userService.GetFromName(res.From);

            if (user == null)
            {
                return(StatusCode(404, "Utilisateur non trouve."));
            }
            Notification notif = new Notification(res);

            notif.Type  = "InvitationStatus";
            notif.About = notif.From + " a accept� votre invitation.";
            _notificationService.Create(notif);
            var result = _eventService.AddGuestToEvent(res.EventId, user.Username);

            _eventService.RemoveInvitationFromEvent(res);
            _invitationService.RemoveInvitationWithId(id);
            return(StatusCode(200, "Invitation acceptee."));
        }
        public void InvitationRepository_ShouldCallUpdateOnce_WhenAcceptInvitationIsCalled()
        {
            // Arrange
            var invitation = new Invitation(new Guid(), "_", Status.Accepted);

            this.invitationRepoMock.Setup(x => x.GetFirst(
                                              It.IsAny <Expression <Func <Invitation, bool> > >(), It.IsAny <Expression <Func <Invitation, object> > >(), It.IsAny <Expression <Func <Invitation, object> > >()))
            .Returns(invitation);
            invitation.User = new User();

            var invitationService = new InvitationService(unitOfWorkMock.Object, invitationRepoMock.Object, userRepoMock.Object, invitationFactoryMock.Object);

            // Act
            invitationService.AcceptInvitation(new Guid());

            // Assert
            invitationRepoMock.Verify(x => x.Update(It.IsAny <Invitation>()), Times.Once);
        }
        public async Task <IActionResult> Signup(SignupParameters parameters)
        {
            var invitation = await _db.Invitations.SingleFirstOrDefaultAsync(i => i.To == parameters.Email);

            if (invitation == null)
            {
                _logger.LogWarning($"Signup attempt with invalid invitation e-mail: {parameters.Email}."); // FIXME: da, rather throw security event with request origin details (IP, port, ...)
                return(NotFound("Invitation not found."));
            }

            var error = await _invitationService.AcceptInvitation(invitation, parameters);

            if (!string.IsNullOrEmpty(error))
            {
                return(BadRequest(error));
            }
            await _db.SaveChangesAsync();

            return(await Login(new LoginParameters
            {
                Email = parameters.Email,
                Password = parameters.Password
            }));
        }