Exemple #1
0
        public IActionResult RegisterUser(RegisterUser newuser)
        {
            User CheckEmail = _iContext.users
                              .Where(u => u.email == newuser.email)
                              .SingleOrDefault();

            if (CheckEmail != null)
            {
                ViewBag.errors = "That email already exists";
                return(RedirectToAction("Register"));
            }
            if (ModelState.IsValid)
            {
                PasswordHasher <RegisterUser> Hasher = new PasswordHasher <RegisterUser>();
                User newUser = new User
                {
                    user_id    = newuser.user_id,
                    first_name = newuser.first_name,
                    last_name  = newuser.last_name,
                    email      = newuser.email,
                    phone      = newuser.phone,
                    password   = Hasher.HashPassword(newuser, newuser.password)
                };
                _iContext.Add(newUser);
                _iContext.SaveChanges();
                ViewBag.success = "Successfully registered";
                return(RedirectToAction("Login"));
            }
            else
            {
                return(View("Register"));
            }
        }
        public TEntity Add(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(Add)} entity must not be null");
            }

            try
            {
                 _instaContext.Add(entity);
                 _instaContext.SaveChanges();

                return entity;
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be saved");
            }
        }