public void DeleteChannelConversation(string username, long channelId)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             context.DeleteChannelUserMessages(channelId, username);
         }
     }
     catch (Exception exception)
     {
         //
     }
 }
 public void DeleteMessage(string username, long messageId)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             context.DeleteMessage(username, messageId);
         }
     }
     catch (Exception exception)
     {
         //
     }
 }
 public void DeleteUserConversation(string username, string usernameOther)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             context.DeleteUserMessages(username, usernameOther);
         }
     }
     catch (Exception exception)
     {
         //
     }
 }
 public void EditMessage(string username, long messageId, string content)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             context.UpdateMessage(username, messageId, content);
         }
     }
     catch (Exception exception)
     {
         //
     }
 }
 public long StoreUserMessage(string username, string usernameOther, string userMessage, DateTime timeSent)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             return(context.StoreUserMessage(userMessage, username, usernameOther, timeSent).FirstOrDefault() ?? 0);
         }
     }
     catch (Exception exception)
     {
         return(0L);
     }
 }
 public List <MessageVM> GetChannelMessages(long channelId)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             var listMessages = context.GetChannelMessages(channelId, 100).ToList();
             return(getMessageVMs(listMessages));
         }
     }
     catch (Exception exception)
     {
         return(new List <MessageVM>());
     }
 }
 public List <UserVM> GetChannelMembers(long channelId)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             var membersList = context.GetChannelMembers(channelId).ToList();
             return(getUserVMs(membersList));
         }
     }
     catch (Exception exception)
     {
         return(new List <UserVM>());
     }
 }
 public List <UserVM> GetAllUsers()
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             var listUsers = context.AllUsers().ToList();
             return(getUserVMs(listUsers));
         }
     }
     catch (Exception exception)
     {
         return(new List <UserVM>());
     }
 }
 public List <MessageVM> GetDirectMessages(string username, string usernameOther)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             var listMessages = context.DirectMessages(username, usernameOther, 100).ToList();
             return(getMessageVMs(listMessages));
         }
     }
     catch (Exception exception)
     {
         return(new List <MessageVM>());
     }
 }
        public void RegisterUser(User user)
        {
            try
            {
                using (ChatAppDBEntities context = new ChatAppDBEntities())
                {
                    context.RegisterUser(user.UserName, user.FirstName, user.LastName, user.Password, user.RegistrationDate);

                    //context.Users.Add(user);
                    //context.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                //
            }
        }
 public List <Channel> GetAllChannels()
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             var            listChannels = context.AllChannels().ToList();
             List <Channel> allChannels  =
                 listChannels.Select(x => new Channel()
             {
                 ChannelId = x.ChannelId, ChannelName = x.ChannelName
             })
                 .ToList();
             return(allChannels);
         }
     }
     catch (Exception exception)
     {
         return(new List <Channel>());
     }
 }
 public List <UserVM> GetUserMessageNotifications(string username, DateTime lastReceived)
 {
     try
     {
         using (ChatAppDBEntities context = new ChatAppDBEntities())
         {
             return
                 (context.GetUserMessageNotifications(username, lastReceived)
                  .ToList()
                  .Select(x => new UserVM()
             {
                 UserName = x
             })
                  .ToList());
         }
     }
     catch (Exception exception)
     {
         return(new List <UserVM>());
     }
 }