public async Task <IActionResult> OnPostAccept(int?Id, int?FriendId)
        {
            if (Id == null || FriendId == null)
            {
                return(NotFound());
            }

            ApplicationUser = await _context.ApplicationUser.FirstOrDefaultAsync(m => m.ID == Id);

            UserFriend = await _context.ApplicationUser.FirstOrDefaultAsync(x => x.ID == FriendId);

            if (ApplicationUser == null || UserFriend == null)
            {
                return(NotFound());
            }

            Friend = await _context.Friend.FirstOrDefaultAsync(x => x.UserID1 == ApplicationUser.ID && x.UserID2 == UserFriend.ID);

            if (Friend == null)
            {
                Friend = await _context.Friend.FirstOrDefaultAsync(x => x.UserID2 == ApplicationUser.ID && x.UserID1 == UserFriend.ID);

                if (Friend == null)
                {
                    return(NotFound());
                }
            }

            Friend.Confirmed = true;

            _context.Attach(Friend).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FriendExists(Friend.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/AppUser/FriendRequests", new { Id = ApplicationUser.ID }));
        }
Пример #2
0
        public async Task <IActionResult> OnPostSaveEditAsync()
        {
            ApplicationUser.Password = Password;

            _context.Attach(ApplicationUser).State = EntityState.Modified;

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

            Password = "";

            return(RedirectToPage("/AppUser/Profile", new { Id = ApplicationUser.ID }));
        }
        public async Task <IActionResult> OnPostSendRequest(int?Id, int?FriendId)
        {
            if (Id == null || FriendId == null)
            {
                return(NotFound());
            }

            ApplicationUser = await _context.ApplicationUser.FirstOrDefaultAsync(m => m.ID == Id);

            UserFriend = await _context.ApplicationUser.FirstOrDefaultAsync(x => x.ID == FriendId);

            if (ApplicationUser == null || UserFriend == null)
            {
                return(NotFound());
            }

            Friend Friend = new Friend
            {
                UserID1   = ApplicationUser.ID,
                UserID2   = UserFriend.ID,
                Confirmed = false
            };

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

            return(RedirectToPage("/AppUser/FindFriends", new { Id = ApplicationUser.ID }));
        }
        public async Task <IActionResult> OnPostUnfriend(int?Id, int?FriendId)
        {
            if (Id == null || FriendId == null)
            {
                return(NotFound());
            }

            ApplicationUser = await _context.ApplicationUser.FirstOrDefaultAsync(m => m.ID == Id);

            UserFriend = await _context.ApplicationUser.FirstOrDefaultAsync(x => x.ID == FriendId);

            if (ApplicationUser == null || UserFriend == null)
            {
                return(NotFound());
            }

            Friend = await _context.Friend.FirstOrDefaultAsync(x => x.UserID1 == ApplicationUser.ID && x.UserID2 == UserFriend.ID);

            if (Friend == null)
            {
                Friend = await _context.Friend.FirstOrDefaultAsync(x => x.UserID2 == ApplicationUser.ID && x.UserID1 == UserFriend.ID);

                if (Friend == null)
                {
                    return(NotFound());
                }
            }

            _context.Friend.Remove(Friend);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/AppUser/Friends", new { Email = ApplicationUser.EmailAddress }));
        }
Пример #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ApplicationUser = await _context.ApplicationUser.FindAsync(id);

            if (ApplicationUser != null)
            {
                _context.ApplicationUser.Remove(ApplicationUser);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #6
0
        public async Task <IActionResult> OnPostSaveEditAsync()
        {
            ApplicationUser.EmailAddress = EmailAddress;
            ApplicationUser.FirstName    = FirstName;
            ApplicationUser.LastName     = LastName;

            HashString Hash = new HashString();

            CurrentPassword = Hash.ComputeSha256Hash(CurrentPassword);

            if (!CurrentPassword.Equals(Password))
            {
                CurrentPasswordErrorMessage = "Current password mismatch!!";
                return(Page());
            }

            ApplicationUser.Password = Hash.ComputeSha256Hash(Password);

            _context.Attach(ApplicationUser).State = EntityState.Modified;

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

            EmailAddress = "";
            FirstName    = "";
            LastName     = "";
            Password     = "";

            return(RedirectToPage("/AppUser/Profile", new { Id = ApplicationUser.ID }));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            ConfirmPasswordErrorMessage = "";
            EmailAddressErrorMessage    = "";

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!ConfirmPassword.Equals(ApplicationUser.Password))
            {
                ConfirmPasswordErrorMessage = "Passwords do not match!!";
                return(Page());
            }

            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) //this error happens if the email address is unique
            {
                HashString Hash = new HashString();
                ApplicationUser.Password = Hash.ComputeSha256Hash(ApplicationUser.Password);

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

                await this.SignInUser(ApplicationUser.EmailAddress, false);

                return(RedirectToPage("/AppUser/Profile", new { Id = ApplicationUser.ID }));
            }
        }