Exemplo n.º 1
0
        public IActionResult Register(RegisterViewModel model)
        {
            System.Console.WriteLine(ModelState.IsValid);
            int num = _context.Users.Where(u => u.Email == model.Email).ToList().Count;

            System.Console.WriteLine(num);
            if (num != 0)
            {
                ViewBag.error = "Email already exists";
                return(View("Index"));
            }
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    Name     = model.Name,
                    Alias    = model.Alias,
                    Email    = model.Email,
                    Password = model.Password,
                };
                System.Console.WriteLine(user.CreatedAt);
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);
                System.Console.WriteLine(user.Password);
                _context.Add(user);
                _context.SaveChanges();
                System.Console.WriteLine(user.UserId);
                HttpContext.Session.SetInt32("UserId", user.UserId);
                return(RedirectToAction("Main", "Ideas"));
            }
            return(View("Index"));
        }
Exemplo n.º 2
0
        public IActionResult IdeaNew(string IdeaText)
        {
            int?UserId = HttpContext.Session.GetInt32("UserId");

            if (UserId == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Idea idea = new Idea
            {
                IdeaText = IdeaText,
                UserId   = (int)UserId,
            };

            _context.Add(idea);
            _context.SaveChanges();
            return(RedirectToAction("Main"));
        }