public User Register(RegisterRequest request)
        {
            var entity = request.ToUserExtension();
            var result = _context.Add <User>(entity);

            _context.SaveChanges();
            return(result.Entity);
        }
Exemple #2
0
        public bool Register(RegisterRequest request)
        {
            var entity = request.ToUserExtension();

            if (_userRepository.GetByMail(entity.Mail) != null)
            {
                return(false);
            }

            _userRepository.Create(entity);
            return(_userRepository.SaveChanges());
        }
        public bool Register(RegisterRequest request)
        {
            User findUser = userRepository.FindByEmail(request.Email);

            if (findUser == null)
            {
                var user = request.ToUserExtension();
                userRepository.Create(user);
                return(userRepository.SaveChanges());
            }
            else
            {
                return(false);
            }
        }
        public User Register(RegisterRequest request)
        {
            request.birthDate = request.birthDate.ToLocalTime();
            var entity            = request.ToUserExtension();
            var userAlreadyExists = _context.Users.Any(x => x.email == request.email);

            if (userAlreadyExists)
            {
                return(null);
            }
            else
            {
                var result = _context.Add <User>(entity);
                _context.SaveChanges();

                MailMessage mailMessage = new MailMessage("*****@*****.**", request.email);
                mailMessage.From = new MailAddress("*****@*****.**", "Travel Check");

                // Specify the email body
                mailMessage.Body = "Verification link: https://localhost:44397/email-verification/" + result.Entity.id;
                // Specify the email Subject
                mailMessage.Subject = "TravelCheck e-mail verification";

                // Specify the SMTP server name and post number
                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                // Specify your gmail address and password
                smtpClient.UseDefaultCredentials = false;

                smtpClient.Credentials = new System.Net.NetworkCredential()
                {
                    UserName = "******",
                    Password = "******"
                };
                // Gmail works on SSL, so set this property to true
                smtpClient.EnableSsl = true;
                // Finall send the email message using Send() method
                smtpClient.Send(mailMessage);

                return(result.Entity);
            }
        }