public void AddUserToChat(TitanWcfService.DataAccesLayer.Entities.User user, TitanWcfService.DataAccesLayer.Entities.Chat chat) { TitanWcfService.DataAccesLayer.Entities.Room room = new TitanWcfService.DataAccesLayer.Entities.Room(); room.UserId = user.Id; room.ChatId = chat.Id; context.Rooms.Add(room); }
public List <TitanWcfService.DataAccesLayer.Entities.Chat> GetChatsOfUser(TitanWcfService.DataAccesLayer.Entities.User user) { List <TitanWcfService.DataAccesLayer.Entities.Chat> userChats = context.Chats.Where(g => context.Rooms.Where(p => p.UserId == user.Id).Select(p => p.ChatId).Contains(g.Id) ).Select(g => g).ToList(); return(userChats); }
public List <TitanWcfService.DataAccesLayer.Entities.User> GetMutualFriends(TitanWcfService.DataAccesLayer.Entities.User user1, TitanWcfService.DataAccesLayer.Entities.User user2) { List <TitanWcfService.DataAccesLayer.Entities.User> user1Friends = GetUserFriends(user1); List <TitanWcfService.DataAccesLayer.Entities.User> user2Friends = GetUserFriends(user2); List <TitanWcfService.DataAccesLayer.Entities.User> mutualFriends = user1Friends.Where(g => user2Friends.Contains(g)).ToList(); return(mutualFriends); }
public List <TitanWcfService.DataAccesLayer.Entities.User> GetUserFriends(TitanWcfService.DataAccesLayer.Entities.User user) { List <int> userChatIds = GetChatsOfUser(user).Select(g => g.Id).ToList(); List <int> userIds = context.Rooms.Where(g => userChatIds.Contains(g.ChatId) && g.UserId != user.Id).Select(g => g.UserId).ToList(); List <TitanWcfService.DataAccesLayer.Entities.User> userFriends = context.Users.Where(g => userIds.Contains(g.Id)).ToList(); return(userFriends); }
public void RemoveUserFromChat(TitanWcfService.DataAccesLayer.Entities.User user, TitanWcfService.DataAccesLayer.Entities.Chat chat) { List <TitanWcfService.DataAccesLayer.Entities.User> usersOfChat = GetUsersOfChat(chat); if (usersOfChat.Count == 1) { RemoveChat(chat); } else { TitanWcfService.DataAccesLayer.Entities.Room room = context.Rooms.FirstOrDefault(g => g.UserId == user.Id && g.ChatId == chat.Id); context.Rooms.Remove(room); } }
public TitanWcfService.DataAccesLayer.Entities.User GetUserById(int id) { TitanWcfService.DataAccesLayer.Entities.User user = context.Users.FirstOrDefault(g => g.Id == id); return(user); }
public void RemoveUser(TitanWcfService.DataAccesLayer.Entities.User user) { context.Users.Remove(user); }
public void AddUser(TitanWcfService.DataAccesLayer.Entities.User user) { context.Users.Add(user); }