public async Task EditBuddyRequestAsync(ClaimsPrincipal user, int requestingGeneralUserId, bool acceptBuddyRequest) { BuddyRequestState state = acceptBuddyRequest ? BuddyRequestState.Matched : BuddyRequestState.Rejected; IGeneralUser generalUser = await _generalUsersService.FindByIdentityAsync(user); await _buddiesRepository.EditBuddyRequestAsync(generalUser.Id, requestingGeneralUserId, state); }
public async Task <IEnumerable <IGeneralUser> > GetBuddyRequestedUsersByStateAsync(int userId, BuddyRequestState state = default) { IQueryable <BuddyRequest> buddies = _databaseContext.BuddyRequests .Where(buddy => buddy.ReceivingGeneralUserId == userId || buddy.RequestingGeneralUserId == userId ); if (state != default) { buddies.Where(buddy => buddy.RequestState == state); } IEnumerable <IGeneralUser> otherGeneralUsers = buddies .Select(x => (userId == x.RequestingGeneralUserId) ? x.ReceivingGeneralUser : x.RequestingGeneralUser) .Select(g => _mapper.Map <IGeneralUser>(g)) .ToList(); return(await Task.FromResult(otherGeneralUsers)); }
public async Task EditBuddyRequestAsync(int receivingGeneralUserId, int requestingGeneralUserId, BuddyRequestState state) { BuddyRequest buddyRequest = _databaseContext.BuddyRequests .Where(buddy => buddy.ReceivingGeneralUserId == receivingGeneralUserId && buddy.RequestingGeneralUserId == requestingGeneralUserId) .FirstOrDefault() ?? throw new ArgumentException($"No buddy request from user {requestingGeneralUserId}."); buddyRequest.RequestState = state; await _databaseContext.SaveChangesAsync(); }