Exemplo n.º 1
0
 public void New(Message msg, MaildbContext context, ApplicationUser appUser)
 {
     msg.MailDate = DateTime.Now;
     msg.MailFrom = appUser.Email;
     context.Messages.Add(msg);
     context.SaveChanges();
 }
Exemplo n.º 2
0
        private List <Message> ShowSpecificMessages(MaildbContext context, AdvancedSearchQuery query)
        {
            List <Message> message = new List <Message>();

            if (query.MailFrom != null)
            {
                message.AddRange(context.Messages.Where(c => c.MailFrom.Contains(query.MailFrom)));
            }
            if (query.MailTo != null)
            {
                message.AddRange(context.Messages.Where(c => c.MailTo.Contains(query.MailTo)));
            }
            if (query.MailTitle != null)
            {
                message.AddRange(context.Messages.Where(c => c.MailTitle.Contains(query.MailTitle)));
            }
            if (query.MailHasWords != null)
            {
                message = HasWords(message, context, query.MailHasWords);
            }
            if (query.MailDoesntHave != null)
            {
                if (query.MailFrom == null && query.MailTo == null && query.MailTitle == null && query.MailHasWords == null)
                {
                    message = context.Messages.ToList();
                    message = DoesntHave(message, context, query.MailDoesntHave);
                }
                else
                {
                    message = DoesntHave(message, context, query.MailDoesntHave);
                }
            }

            return(Encoding(message));
        }
Exemplo n.º 3
0
 public MessagesController(MaildbContext context, IMessageControl msgCntrl, IAdvancedSearch advSearch, IPagingInfo pageInfo)
 {
     _context   = context;
     _msgCntrl  = msgCntrl;
     _advSearch = advSearch;
     _pageInfo  = pageInfo;
 }
Exemplo n.º 4
0
        private List <Message> ShowAllMessages(MaildbContext context)
        {
            List <Message> messages = new List <Message>();

            messages = context.Messages.ToList();

            return(Encoding(messages));
        }
Exemplo n.º 5
0
 public void DeleteFriend(string friendName)
 {
     using (var _context = new MaildbContext())
     {
         var friend = _context.ChatFriends.Single(c => c.Friend == friendName || c.FriendUserName == friendName);
         _context.ChatFriends.Remove(friend);
         _context.SaveChanges();
         Clients.Caller.friendsToList(CreateFriendsList(Context.User.Identity.Name, _context));
     }
 }
Exemplo n.º 6
0
        private List <Message> HasWords(List <Message> messages, MaildbContext context, string MailHasWords)
        {
            string[] hasWords = MailHasWords.Split(' ');

            foreach (var word in hasWords)
            {
                messages.AddRange(context.Messages.Where(c => c.MailContent.Contains(word) || c.MailTitle.Contains(word)));
            }

            return(messages);
        }
Exemplo n.º 7
0
 public void Delete(MaildbContext _context, string[] rows)
 {
     if (rows != null)
     {
         foreach (var row in rows)
         {
             int id     = Decode(row);
             var delRow = _context.Messages.First(c => c.ID == id);
             _context.Messages.Remove(delRow);
         }
         _context.SaveChanges();
     }
 }
Exemplo n.º 8
0
        private List <Message> DoesntHave(List <Message> messages, MaildbContext context, string MailDoesntHave)
        {
            string[] doesntHave = MailDoesntHave.Split(' ');

            foreach (var word in doesntHave)
            {
                Message toRemove = messages.First(c => c.MailContent.Contains(word) || c.MailTitle.Contains(word));
                if (toRemove != null)
                {
                    messages.Remove(toRemove);
                }
            }

            return(messages);
        }
Exemplo n.º 9
0
        public List <Message> FindMessages(AdvancedSearchQuery query, MaildbContext context)
        {
            query = SetQueryNull(query);
            List <Message> _messages = null;

            if (query != null)
            {
                _messages = ShowSpecificMessages(context, query);
            }
            else
            {
                _messages = ShowAllMessages(context);
            }

            return(_messages.OrderByDescending(m => m.MailDate).Distinct().ToList());
        }
Exemplo n.º 10
0
        private IEnumerable <ChatFriend> CreateFriendsList(string userName, MaildbContext _context)
        {
            List <ChatFriend> ChatFriends = new List <ChatFriend>();

            ChatFriends = _context.ChatFriends.Include(c => c.ApplicationUser).Where(c => c.ApplicationUser.Email == userName || c.ApplicationUser.UserName == userName).ToList();
            foreach (var friend in ChatFriends)
            {
                foreach (var user in ConnectedUsers)
                {
                    if (user.UserName == friend.Friend)
                    {
                        friend.ConnectionID = user.ConnectionId;
                    }
                }
            }
            return(ChatFriends.OrderBy(c => c.FriendUserName));
        }
Exemplo n.º 11
0
        public void AddFriend(string friendName)
        {
            ChatFriend      chtFr  = new ChatFriend();
            var             me     = Context.User.Identity.Name;
            ApplicationUser friend = new ApplicationUser();

            using (var _context = new MaildbContext())
            {
                var appUser = _context.Users.First(c => c.Email == me || c.UserName == me);
                friend = _context.Users.First(c => c.Email == friendName || c.UserName == friendName);
                chtFr.ApplicationUser = appUser;
                chtFr.Friend          = friend.Email;
                chtFr.FriendUserName  = friend.UserName;
                _context.ChatFriends.Add(chtFr);
                _context.SaveChanges();
                Clients.Caller.friendsToList(CreateFriendsList(me, _context));
            }
        }
Exemplo n.º 12
0
        public void Connect(string userName)
        {
            string id = Context.ConnectionId;

            using (var _context = new MaildbContext())
            {
                string userEmail = _context.Users.Single(c => c.UserName == userName).Email;
                if (ConnectedUsers.Count(x => x.ConnectionId == id) == 0)
                {
                    ConnectedUsers.Add(new UserDetails {
                        ConnectionId = id, UserName = userName, UserEmail = userEmail
                    });

                    Clients.Caller.onConnected(id, userName, ConnectedUsers, CreateFriendsList(userName, _context));

                    Clients.AllExcept(id).onNewUserConnected(id, userName, userEmail);
                }
            }
        }
Exemplo n.º 13
0
 public HomeControllerTest(MaildbContext context)
 {
     _context = context;
 }
Exemplo n.º 14
0
 public List <Message> GetAllSentMessages(MaildbContext _context, ApplicationUser appUser)
 {
     return(_context.Messages.Where(c => c.MailFrom == appUser.Email).OrderByDescending(c => c.MailDate).ToList());
     //return rtnMsg();
 }
Exemplo n.º 15
0
 public ApplicationUserStore(MaildbContext context)
     : base(context)
 {
 }
Exemplo n.º 16
0
 public List <Message> GetAllMessages(MaildbContext _context, ApplicationUser appUser)
 {
     return(_context.Messages.ToList());
     //return rtnMsg();
 }
Exemplo n.º 17
0
 public static List <Message> Receive(MaildbContext _context)
 {
     return(_context.Messages.Where(c => c.MailTo == "*****@*****.**").ToList());
 }