Ejemplo n.º 1
0
        public async Task <MaskedEmailWithPassword> CreateMaskedEmail(string userId, string name, string passwordHash, string description, bool enableForwarding)
        {
            var record = await GetProfileEntityGraphForUpdate(userId);

            if (record == null)
            {
                throw Error.NoSuchProfile(userId);
            }

            string clearTextPassword = null;

            var emailAddress = await MakeUniqueAddressAsync();

            if (String.IsNullOrEmpty(passwordHash))
            {
                clearTextPassword = MakePassword();
                passwordHash      = MakePassword();
            }

            await commands_.CreateMaskedEmailAsync(
                emailAddress
                , record.ForwardingAddress
                , passwordHash
                );

            var address = new Address
            {
                Name             = name,
                Description      = description,
                EmailAddress     = emailAddress,
                EnableForwarding = enableForwarding,
                CreatedUtc       = DateTime.UtcNow,
            };

            record.Addresses.Add(address);
            await context_.SaveChangesAsync();

            // TODO: Received ?

            var result = MaskedEmailWithPassword.Clone(address.ToModel());

            result.Password = clearTextPassword;

            return(result);
        }