Ejemplo n.º 1
0
        public async Task <IActionResult> Registration(RegistrationViewModel UserView)
        {
            byte[] hash = null;
            byte[] salt = null;

            PasswordEncryption.CreatePasswordHash(UserView.ConfirmPassword, out hash, out salt);
            //UserView.Error = false;
            User user = new User
            {
                UserID            = UserView.UserID,
                FirstName         = UserView.FirstName,
                LastName          = UserView.LastName,
                SecurityQuestion1 = UserView.SecurityQuestion1,
                SecurityQuestion2 = UserView.SecurityQuestion2,
                PasswordHash      = hash,
                PasswordSalt      = salt
            };

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

                return(RedirectToAction(nameof(Login)));
            }
            catch (DbUpdateException ex)
            {
                // Control of code reached catch block means there was an exception Adding user instance which means same email entry
                ViewData["Exists"] = true;

                return(View(UserView)); // Sending to delete page if an account with same email exists
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(BrandViewModel model)
        {
            if (ModelState.IsValid)
            {
                var brand = new Brand
                {
                    BrandName = model.BrandName
                };
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nameof(Index)));
        }