示例#1
0
        public async Task <IActionResult> AddFriend([Bind(include: "FriendId, UserId")] ApplicationUserFriend applicationUserFriend)
        {
            // Check to see if the model is valid
            if (ModelState.IsValid)
            {
                // Add the record to the database if it is valid.
                _db.UserFriends.Add(applicationUserFriend);

                await _db.SaveChangesAsync();
            }

            // Then redirect the user back to the Index function
            return(RedirectToAction("Index", "Home"));
        }
示例#2
0
        public async Task <IActionResult> RemoveFriend([Bind(include: "FriendId, UserId")] ApplicationUserFriend applicationUserFriend)
        {
            if (ModelState.IsValid)
            {
                // Delete the record from the database if the model is valid, after we get the record.
                ApplicationUserFriend applicationUserFriendRecord = await _db.UserFriends.FirstOrDefaultAsync(m => m.UserId == applicationUserFriend.UserId && m.FriendId == applicationUserFriend.FriendId);

                _db.UserFriends.Remove(applicationUserFriendRecord);

                await _db.SaveChangesAsync();
            }

            // Then redirect the user back to the Index function
            return(RedirectToAction("Index", "Home"));
        }