Пример #1
0
        public async Task <IActionResult> PutPreferences(int id, ApplicationUser applicationUser)
        {
            var userList = _context.ApplicationUsers.Where(u => u.username.Equals(applicationUser.username) && u.Id == id);

            if (!(userList.Count() > 0) || !SecurePasswordHasher.Verify(applicationUser.password, userList.FirstOrDefault().password))
            {
                return(BadRequest());
            }

            var user = userList.FirstOrDefault();

            user.sitePref              = applicationUser.sitePref;
            user.reversePref           = applicationUser.reversePref;
            user.typePref              = applicationUser.typePref;
            user.sortPref              = applicationUser.sortPref;
            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplicationUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.ApplicationUser.Add(ApplicationUser);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!ApplicationUser.Password.Equals(ConfirmPassword))
            {
                ConfirmPasswordErrorMessage = "Passwords does not match!!";
            }
            else
            {
                try
                {
                    // The Contains method is run on the database
                    var email = (from u in _context.ApplicationUser
                                 where (u.EmailAddress == ApplicationUser.EmailAddress)
                                 select u.EmailAddress).Single();

                    EmailAddressErrorMessage = "An account with this Email Address already exists!!";
                    return(Page());
                }
                catch (InvalidOperationException)
                {
                    string encryptedPass = EncryptPassword(ApplicationUser.Password);
                    ApplicationUser.Password = encryptedPass;

                    _context.ApplicationUser.Add(ApplicationUser);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Index"));
                }
            }

            return(Page());
        }