public async Task AcceptFriendRequestAsync(int friendRequestId) { using (var transaction = _repository.BeginTransaction()) { await ChangeFriendRequestStatus(friendRequestId, FriendshipStatus.Lasts); var friendship = await GetFriendRequestAsync(friendRequestId); if (friendship == null) { throw new FriendRequestException("The friend request you referenced does not exist in the system."); } var groupAll = await _groupsService.GetGroupByNamesAsync( friendship.UserFrom.UserName, _groupsOptions.AllFriendsGroupName); await _groupsService.AddUserToGroupAsync(friendship.UserTo.UserName, groupAll.Id); groupAll = await _groupsService.GetGroupByNamesAsync( friendship.UserTo.UserName, _groupsOptions.AllFriendsGroupName); await _groupsService.AddUserToGroupAsync(friendship.UserFrom.UserName, groupAll.Id); transaction.Commit(); } }
public async Task <IActionResult> AddUserToGroup(string userName, int groupId) { try { await _groupsService.AddUserToGroupAsync(userName, groupId); } catch (ApplicationException exception) { return(Error.FromController(this).ErrorJson("Error!", exception.Message, HttpStatusCode.BadRequest)); } catch { return(Error.FromController(this).ErrorJson( "Error!", "An unexpected error has occured while processing your request.", HttpStatusCode.InternalServerError)); } return(Ok( new { title = "Group updated.", message = $"User {userName} was added to this group. " + "Refresh this page to see changes." })); }