示例#1
0
        public async Task <bool> RemoveClientFromChat(RemoveClientFromChat container)
        {
            using (var db = new DBChat())
            {
                foreach (var client in container.NameOfClients)
                {
                    ClientsInChats clientInChat = new ClientsInChats
                    {
                        ClientID = client,
                        ChatID   = container.NumberChat,
                    };
                    db.ClientsInChats.Attach(clientInChat);
                    db.ClientsInChats.Remove(clientInChat);
                }
                try
                {
                    int taskDb = await db.SaveChangesAsync();

                    if (taskDb == 0)
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        public async Task <bool> RemoveChat(int numberChat)
        {
            using (var db = new DBChat())
            {
                Chats chat = new Chats
                {
                    ChatID = numberChat,
                };
                db.PoolChat.Attach(chat);
                db.PoolChat.Remove(chat);

                try
                {
                    int taskDb = await db.SaveChangesAsync();

                    if (taskDb == 0)
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
        public int CreatNewChat(CreatingChatInfo container)
        {
            int numberChat = -1;

            using (var db = new DBChat())
            {
                Chats chat = new Chats
                {
                    Type      = "Group",
                    OwnerChat = container.NameOfClientSender,
                };
                db.PoolChat.Add(chat);
                try
                {
                    Task <int> taskDb = db.SaveChangesAsync();

                    if (taskDb.Result == 0)
                    {
                        return(numberChat);
                    }
                    numberChat = chat.ChatID;
                }
                catch (Exception e)
                {
                    return(numberChat);
                }
            }
            return(numberChat);
        }
示例#4
0
        public async Task <bool> AddNewMessage(MessageInfoForDataBase container)
        {
            using (var db = new DBChat())
            {
                Messages message = new Messages
                {
                    ChatID = container.NumberChat,
                    From   = container.FromMessage,
                    Text   = container.Text,
                    Time   = container.Time.ToString(),
                };
                db.Messages.Add(message);
                try
                {
                    int taskDb = await db.SaveChangesAsync();

                    if (taskDb == 0)
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(true);
        }
示例#5
0
        public async Task <bool> AddNewClient(ClientInfo container)
        {
            using (var db = new DBChat())
            {
                PoolClients client = new PoolClients
                {
                    ClientID = container.NameClient,
                    Clients  = new List <ClientsInChats>(),
                };
                db.PoolClients.Add(client);
                try
                {
                    int taskDb = await db.SaveChangesAsync();

                    if (taskDb == 0)
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#6
0
        public ConcurrentDictionary <string, Guid> GetInfoAboutAllClient()
        {
            ConcurrentDictionary <string, Guid> allClientInfo = new ConcurrentDictionary <string, Guid>();

            using (var db = new DBChat())
            {
                foreach (var item in db.PoolClients)
                {
                    allClientInfo.TryAdd(item.ClientID, Guid.Empty);
                }
            }
            return(allClientInfo);
        }
示例#7
0
 public RequestManagerDb(GeneralChatInfo generalChatInfo)
 {
     using (var db = new DBChat())
     {
         var count = db.PoolChat.Where(Chat => Chat.ChatID == generalChatInfo.NumberGeneralChat).Count();
         if (count == 0)
         {
             db.PoolChat.Add(new Chats()
             {
                 ChatID    = generalChatInfo.NumberGeneralChat,
                 Type      = generalChatInfo.TypeGeneralChat,
                 OwnerChat = generalChatInfo.OwnerGeneralChat
             });
             db.SaveChanges();
         }
     }
 }
示例#8
0
        public ConcurrentDictionary <int, List <MessageInfo> > GetAllMessageFromChats()
        {
            ConcurrentDictionary <int, List <MessageInfo> > allMessage = new ConcurrentDictionary <int, List <MessageInfo> >();

            using (var db = new DBChat())
            {
                foreach (var item in db.Messages)
                {
                    List <MessageInfo> messages = new List <MessageInfo>();
                    var MessagesOfChats         = db.Messages
                                                  .Where(Client => Client.ChatID == item.ChatID);
                    foreach (var message in MessagesOfChats)
                    {
                        messages.Add(new MessageInfo(message.From, message.Text, DateTime.Parse(message.Time)));
                    }
                    allMessage.TryAdd(item.ChatID, messages);
                }
            }
            return(allMessage);
        }
示例#9
0
        public ConcurrentDictionary <int, InfoChat> GetInfoAboutAllChat()
        {
            ConcurrentDictionary <int, InfoChat> allChatInfo = new ConcurrentDictionary <int, InfoChat>();

            using (var db = new DBChat())
            {
                foreach (var item in db.PoolChat)
                {
                    List <string> clientsName    = new List <string>();
                    var           ClientsOfChats = db.ClientsInChats
                                                   .Where(Client => Client.ChatID == item.ChatID);
                    foreach (var Client in ClientsOfChats)
                    {
                        clientsName.Add(Client.ClientID);
                    }
                    allChatInfo.TryAdd(item.ChatID, new InfoChat {
                        OwnerChat = item.OwnerChat, NameOfClients = clientsName
                    });
                }
            }
            return(allChatInfo);
        }
示例#10
0
        public ConcurrentDictionary <string, ClientProperties> GetInfoAboutLinkClientToChat()
        {
            ConcurrentDictionary <string, ClientProperties> allLinkInfo = new ConcurrentDictionary <string, ClientProperties>();

            using (var db = new DBChat())
            {
                foreach (var item in db.PoolClients)
                {
                    List <int> numbersChat    = new List <int>();
                    var        ChatsOfClients = db.ClientsInChats
                                                .Where(Client => Client.ClientID == item.ClientID);
                    foreach (var Chat in ChatsOfClients)
                    {
                        numbersChat.Add(Chat.ChatID);
                    }
                    allLinkInfo.TryAdd(item.ClientID, new ClientProperties {
                        NumbersChat = numbersChat
                    });
                }
            }
            return(allLinkInfo);
        }