Ejemplo n.º 1
0
        public async Task <UserDTO> Register(NewUserDTO creatingUser)
        {
            var userSN = new NewUserSocialNetworkDTO()
            {
                UId              = creatingUser.UId,
                ProviderName     = creatingUser.ProviderName,
                SocialNetworkUrl = creatingUser.ProviderUrl,
            };

            var user = _mapper.Map <User>(creatingUser);

            user.CreatedAt = DateTime.Now;
            _context.Add(user);
            await _context.SaveChangesAsync();

            var userDto = _mapper.Map <UserDTO>(user);

            userSN.UserId = userDto.Id;
            var userSNEntity = _mapper.Map <UserSocialNetwork>(userSN);

            _context.Add(userSNEntity);
            await _context.SaveChangesAsync();

            var emailModel = _emailBuilder.GetSignUpLetter(creatingUser.Email, creatingUser.FirstName);
            await _emailService.SendEmailAsync(new List <string> {
                emailModel.Email
            }, emailModel.Subject, emailModel.Title, emailModel.Body);

            return(_mapper.Map <UserDTO>(user));
        }
Ejemplo n.º 2
0
        public async Task <UserDTO> Register(NewUserDTO creatingUser)
        {
            var userSNEntity = new UserSocialNetwork()
            {
                UId              = creatingUser.UId,
                ProviderName     = creatingUser.ProviderName,
                SocialNetworkUrl = creatingUser.ProviderUrl,
            };

            var user = _mapper.Map <User>(creatingUser, opt => opt.AfterMap((src, dst) =>
            {
                dst.CreatedAt          = DateTime.Now;
                dst.UserSocialNetworks = new List <UserSocialNetwork> {
                    userSNEntity
                };
            }));

            _context.Add(user);
            await _context.SaveChangesAsync();

            var emailModel = _emailBuilder.GetSignUpLetter(creatingUser.Email, creatingUser.FirstName);
            await _emailService.SendEmailAsync(new List <string> {
                emailModel.Email
            }, emailModel.Subject, emailModel.Title, emailModel.Body);

            return(_mapper.Map <UserDTO>(user));
        }