Exemplo n.º 1
0
        public async Task <IActionResult> AcceptFriendRequest(string usernameToBefriend, string returnUrl = null)
        {
            var loggedUserId     = _userManager.GetUserId(User);
            var userToBefriendId = await _userService.IdByUsernameAsync(usernameToBefriend);

            if (!await _userService.ValidateFriendshipAcceptance(loggedUserId, userToBefriendId))
            {
                return(View(GlobalConstants.AccessDeniedView));
            }

            var result = await _userService.AcceptFriendshipAsync(User.Identity.Name, usernameToBefriend);

            if (!result)
            {
                return(View(GlobalConstants.AccessDeniedView));
            }

            if (!string.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(RedirectToAction(nameof(Visit), new { username = usernameToBefriend }));
        }