Esempio n. 1
0
        public async Task <ToConfirm> AddAsync(string email)
        {
            ToConfirm toConfirm;

            _toConfirms.Add(
                toConfirm = new ToConfirm
            {
                Id             = _toConfirms.Max(tc => tc.Id) + 1,
                EmailToConfirm = email,
                TimeStamp      = DateTime.Now,
                Token          = email.GetHashCode()
            }
                );

            return(await Task.Run(() => toConfirm));
        }
        /// <summary>
        /// Add a ToConfirm to the database, representing
        /// a User's email that must be confirmed
        /// </summary>
        /// <param name="email">The User's email, which creates the unique token</param>
        /// <returns>The new ToConfirm</returns>
        public async Task <ToConfirm> AddAsync(string email)
        {
            var confirm = await _context.ToConfirms.FirstOrDefaultAsync(
                tc => tc.EmailToConfirm == email
                );

            if (confirm == null)
            {
                await _context.ToConfirms.AddAsync(
                    confirm = new ToConfirm()
                {
                    EmailToConfirm = email,
                    Token          = email.GetHashCode(), // The token is created via the email's hash code
                    TimeStamp      = DateTime.Now
                }
                    );
            }
            await _context.SaveChangesAsync();

            return(confirm);
        }