Пример #1
0
 public static void Register(Users user)
 {
     using (NochDBEntities _db = new NochDBEntities())
     {
         try
         {
             _db.Users.Add(user);
             _db.SaveChanges();
         }
         catch (Exception ex) { }
     }
 }
Пример #2
0
 public static void MakeChannel(Channels c)
 {
     using (NochDBEntities _db = new NochDBEntities())
     {
         try
         {
             _db.Channels.Add(c);
             _db.SaveChanges();
         }
         catch (Exception ex) { }
     }
 }
Пример #3
0
 public static void SendMessage(Messages message)
 {
     using (NochDBEntities _db = new NochDBEntities())
     {
         try
         {
             _db.Messages.Add(message);
             _db.SaveChanges();
         }
         catch (Exception ex) { }
     }
 }
Пример #4
0
        public static List <Channels> GetChannelsForDomain(int domainId)
        {
            using (NochDBEntities _db = new NochDBEntities())
            {
                var channels = new List <Channels>();

                try
                {
                    IQueryable <Channels> query = (from c in _db.Channels
                                                   where c.DomainID == domainId
                                                   select c).Include("Messages").AsNoTracking();
                    channels = query.ToList();
                }
                catch (Exception ex) { }

                return(channels);
            }
        }
Пример #5
0
        public static List <Messages> GetMessages(int channelId, int messageCount)
        {
            var messages = new List <Messages>();

            using (NochDBEntities _db = new NochDBEntities())
            {
                try
                {
                    IQueryable <Messages> query = (from m in _db.Messages
                                                   where m.ChannelID == channelId
                                                   select m).Take(messageCount);
                    messages = query.ToList();
                }
                catch (Exception ex) { }
            }

            return(messages);
        }
Пример #6
0
        public static string GetUsername(int userId)
        {
            string username = "";

            using (NochDBEntities _db = new NochDBEntities())
            {
                try
                {
                    var query = from u in _db.Users
                                where u.UserID == userId
                                select u.Username;

                    username = query.FirstOrDefault();
                }
                catch (Exception ex) { }
            }

            return(username);
        }
Пример #7
0
        public static List <Domains> GetDomainsForUser(int userId)
        {
            using (NochDBEntities _db = new NochDBEntities())
            {
                var domains = new List <Domains>();
                try
                {
                    IQueryable <Domains> query = (from d in _db.Domains
                                                  join ud in _db.UserDomains
                                                  on d.DomainID equals ud.DomainID
                                                  where ud.UserID == userId
                                                  select d).Include("Channels").AsNoTracking();
                    domains = query.ToList();
                }
                catch (Exception ex) { }

                return(domains);
            }
        }
Пример #8
0
        public static int MakeDomain(Domains d, UserDomains ud)
        {
            using (NochDBEntities _db = new NochDBEntities())
            {
                try
                {
                    _db.Domains.Add(d);
                    _db.SaveChanges();

                    ud.DomainID = d.DomainID;

                    _db.UserDomains.Add(ud);
                    _db.SaveChanges();

                    return(d.DomainID);
                }
                catch (Exception ex) { }
            }

            return(-1);
        }
Пример #9
0
        public static void UpdateMessage(int userId, int msgId, int channelId, string msg)
        {
            using (NochDBEntities _db = new NochDBEntities())
            {
                try
                {
                    Messages message = new Messages();
                    message.MessageID = msgId;

                    _db.Messages.Attach(message);

                    message.UserID    = userId;
                    message.ChannelID = channelId;
                    message.Content   = msg;
                    message.IsEdited  = true;
                    message.UpdatedOn = DateTime.Now;

                    _db.SaveChanges();
                }
                catch (Exception ex) { }
            }
        }