public async Task SendRequest(FriendRequestInputDto requestInputDto) { if (await _dbContext.FriendRequests.AnyAsync(e => (e.RequestedFromId == requestInputDto.RequestedFromId && e.RequestedToId == requestInputDto.RequestedToId) || (e.RequestedFromId == requestInputDto.RequestedToId && e.RequestedToId == requestInputDto.RequestedFromId))) { throw new System.Exception("User already Send Request"); } var request = _mapper.Map <FriendRequest>(requestInputDto); await _dbContext.AddAsync(request); await _dbContext.SaveChangesAsync(); await _notificationService.InsertNotification(new NotificationDto { UserId = request.RequestedToId, Message = $"you got new FriendRequest" }); }
public async Task SendRequest([FromBody] FriendRequestInputDto requestInputDto) { requestInputDto.RequestedFromId = UserId; await requestService.SendRequest(requestInputDto); }