public Chat GetChatById(int chatId, Include <Chat> include = null) { var chat = ChatProvider.All(include).FirstOrDefault(c => c.ChatId == chatId); if (chat == null) { throw new ServiceException { Code = StatusCode.ChatNotFoundError }; } return(chat); }
public Chat GetOrCreateChatWithUser(User sender, User receiver, Include <Chat> include = null) { var chat = ChatProvider.All(include) .Include(c => c.UserChats) .ThenInclude(uc => uc.User) .FirstOrDefault(c => c.UserChats.Select(uc => uc.User.UserId).Contains(receiver.UserId)); if (chat == null) { chat = new Chat { Type = ChatType.Personal }; ChatProvider.Add(chat); AddUserToChat(sender, chat); AddUserToChat(receiver, chat); } return(chat); }
public IQueryable <Chat> GetUserChats(User user) { return(ChatProvider.All().Include(c => c.UserChats) .Where(c => c.UserChats.Any(uc => uc.UserId == user.UserId))); }