Exemplo n.º 1
0
        public bool RemoveUserFromChat(User user, Chat chat)
        {
            try
            {
                List <User> usersOfChat = GetUsersOfChat(chat);

                if (usersOfChat.Count == 1)
                {
                    RemoveChat(chat);
                }
                else
                {
                    using (var context = new TitanNetworkContext())
                    {
                        Room room = context.Rooms.FirstOrDefault(g => g.UserId == user.Id && g.ChatId == chat.Id);
                        context.Entry(room).State = EntityState.Deleted;
                        context.SaveChanges();
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public BotCache GetBotCacheExistance(string title)
        {
            BotCache cacheFound;

            using (var context = new TitanNetworkContext())
            {
                cacheFound = context.BotCaches.FirstOrDefault(g => g.Title == title);
            }

            return(cacheFound);
        }
        public Message GetMessageById(int id)
        {
            Message msg;

            using (var context = new TitanNetworkContext())
            {
                msg = context.Messages.FirstOrDefault(g => g.Id == id);
            }

            return(msg);
        }
Exemplo n.º 4
0
        public Chat GetChatById(int id)
        {
            Chat chat;

            using (var context = new TitanNetworkContext())
            {
                chat = context.Chats.FirstOrDefault(g => g.Id == id);
            }

            return(chat);
        }
Exemplo n.º 5
0
 public bool AddMessageLog(MessageLog log)
 {
     try
     {
         using (var context = new TitanNetworkContext())
         {
             context.Entry(log).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
 public bool AddBotCache(BotCache cache)
 {
     try
     {
         using (var context = new TitanNetworkContext())
         {
             context.Entry(cache).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
 public bool UpdateMessage(Message message)
 {
     try
     {
         using (var context = new TitanNetworkContext())
         {
             context.Entry(message).State = EntityState.Modified;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 8
0
 public bool RemoveChat(Chat chat)
 {
     try
     {
         using (var context = new TitanNetworkContext())
         {
             context.Entry(chat).State = EntityState.Deleted;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 9
0
        public List <Message> GetMessagesFromChat(Chat chat)
        {
            try
            {
                List <Message> chatMessages;

                using (var context = new TitanNetworkContext())
                {
                    chatMessages = context.Messages.Where(g => g.ChatId == chat.Id).ToList();
                }

                return(chatMessages);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 10
0
 public bool AddUserToChat(User user, Chat chat)
 {
     try
     {
         using (var context = new TitanNetworkContext())
         {
             Room room = new Room();
             room.UserId = user.Id;
             room.ChatId = chat.Id;
             context.Rooms.Add(room);
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 11
0
        public List <User> GetUsersOfChat(Chat chat)
        {
            try
            {
                List <User> users;

                using (var context = new TitanNetworkContext())
                {
                    List <int> userIds = context.Rooms.Where(g => g.ChatId == chat.Id).Select(g => g.UserId).ToList();
                    users = context.Users.Where(g => userIds.Contains(g.Id
                                                                      )).ToList();
                }

                return(users);
            }
            catch
            {
                return(null);
            }
        }
 public BaseProvider()
 {
     Context = new TitanNetworkContext();
 }
Exemplo n.º 13
0
 public CustomRoleStore(TitanNetworkContext context)
     : base(context)
 {
 }
Exemplo n.º 14
0
 public CustomUserStore(TitanNetworkContext context)
     : base(context)
 {
 }