Exemplo n.º 1
0
        private static NewMemberParameters MapMember_(RegisterMemberRequest request, string encryptedPassword)
        {
            Require.NotNull(request, "query");
            Require.NotNullOrEmpty(encryptedPassword, "encryptedPassword");

            return(new NewMemberParameters {
                CompanyName = request.CompanyName,
                Email = request.Email,
                EncryptedPassword = encryptedPassword,
                FirstName = request.FirstName,
                LastName = request.LastName,
                NewsletterChecked = request.NewsletterChecked,
            });
        }
Exemplo n.º 2
0
        public VoidOrBreak RegisterMember(RegisterMemberRequest request)
        {
            Require.NotNull(request, "request");

            // 1. On vérifie que l'addresse email n'est pas déjà prise.

            var password = _queries.GetPassword(request.Email);

            if (!String.IsNullOrEmpty(password))
            {
                return(VoidOrBreak.Break(Strings.MemberService_EmailAlreadyTaken));
            }

            // 2. Génération d'un nouveau mot de passe.

            password = CreatePassword_();

            // 3. Création du compte en base de données.

            var cmdParameters = MapMember_(request, EncryptPassword_(password));

            _commands.NewMember(cmdParameters);

            var member = new Member {
                Email     = request.Email,
                FirstName = request.FirstName,
                LastName  = request.LastName,
            };

            // 4. On enclenche tout de suite l'événement (au cas où les opérations suivantes échouent).

            OnMemberCreated_(new MemberCreatedEventArgs(member));

            // 5. Envoi des notifications.

            if (request.Recipients != MessageRecipients.None)
            {
                _messenger.Publish(new NewMemberMessage {
                    CompanyName  = request.CompanyName,
                    EmailAddress = member.EmailAddress,
                    Password     = password,
                    Recipients   = request.Recipients,
                });
            }

            return(VoidOrBreak.Void);
        }