Example #1
0
        public void Handle(AddFileCommand command)
        {
            User owner = currentUserSource.GetCurrentUser();

            if (owner == null)
            {
                throw new NotFoundException("The current user cannot be found in the database.");
            }

            var dateCreated = DateTime.UtcNow;
            var size        = command.Content.Length;
            var file        = new File(null, command.FileName, command.Description, size, command.MimeType, dateCreated, owner);

            fileRepository.Save(file);

            registrator.Committed += () =>
            {
                eventBus.Publish <FileAddedEvent, File>(file);
                // save the file after commit so we don't end up with a file on disk but no entity in the database
                // which would mean there isn't a safe way to delete it
                fileStorage.SaveFile(file, command.Content);
            };
        }
        public async Task <OperationResult> RegisterUser(string username, string email, string password)
        {
            var user = new User()
            {
                Username = username,
                Email    = email
            };

            OperationResult result = await userManager.CreateAsync(user, password);

            if (!result.IsValid)
            {
                return(result);
            }

            eventBus.Publish <UserRegisteredEvent, UserInfo>(new UserInfo(user.Id, user.Username, user.Email));

            try
            {
                await emailConfirmationService.SendConfirmationEmail(user);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Failed to send a confirmation e-mail.");
                const string errorMessage =
                    "The account has been successfully created, but the server failed to deliver " +
                    "an account confirmation e-mail. Please try to use the resend option later" +
                    " to activate your account.";
                return(OperationResult.Invalid(new List <OperationError>()
                {
                    new OperationError(errorMessage, OperationError.ErrorType.ProcessingError)
                }));
            }

            return(OperationResult.Valid());
        }
Example #3
0
 public void PublishAfterCommit <TEvent, TMessage>(TMessage message) where TEvent : IEvent <TMessage>
 {
     registrator.Committed += () => eventBus.Publish <TEvent, TMessage>(message);
 }