private IEnumerable <IMessage> GetFilteredMessages(MessageFilteringParams messageFilteringParams)
        {
            var filteredByUser = FilteredByUser(messageFilteringParams);
            var filteredByText = FilteredByText(messageFilteringParams);
            var filteredByDate = FilteredByDate(messageFilteringParams);

            if (messageFilteringParams.UsersSortOptions == SortOptions.AND)
            {
                filteredByUser = filteredByUser.Intersect(filteredByText, new MessageComparer());
            }
            else if (messageFilteringParams.UsersSortOptions == SortOptions.OR)
            {
                filteredByUser = filteredByUser.Union(filteredByText, new MessageComparer());
            }

            if (messageFilteringParams.MessageTextSortOptions == SortOptions.AND)
            {
                filteredByUser = filteredByUser.Intersect(filteredByDate, new MessageComparer());
            }
            else if (messageFilteringParams.MessageTextSortOptions == SortOptions.OR)
            {
                filteredByUser = filteredByUser.Union(filteredByDate, new MessageComparer());
            }
            return(filteredByUser);
        }
        private IEnumerable <IMessage> FilteredByDate(MessageFilteringParams messageFilteringParams)
        {
            var filteredMessages = from i in Messages
                                   where i.ReceivingTime <messageFilteringParams.BeforeDate &&
                                                          i.ReceivingTime> messageFilteringParams.FromDate
                                   select i;

            return(filteredMessages);
        }
        private IEnumerable <IMessage> FilteredByText(MessageFilteringParams messageFilteringParams)
        {
            if (string.IsNullOrEmpty(messageFilteringParams.MessageText))
            {
                return(Messages);
            }
            var filteredMessages = from i in Messages
                                   where i.Text.Contains(messageFilteringParams.MessageText)
                                   select i;

            return(filteredMessages);
        }
        private IEnumerable <IMessage> FilteredByUser(MessageFilteringParams messageFilteringParams)
        {
            if (string.IsNullOrEmpty(messageFilteringParams.SelectedUser))
            {
                return(Messages);
            }
            var filteredMessages = from i in Messages
                                   where i.User == messageFilteringParams.SelectedUser
                                   select i;

            return(filteredMessages);
        }
        public IEnumerable <IMessage> GetMessages(MessageFilteringParams messageFilteringParams)
        {
            var filteredMessages = GetFilteredMessages(messageFilteringParams);
            var filteredMessagesForFormatting = from m in filteredMessages
                                                select new Message()
            {
                User          = m.User,
                Text          = m.Text,
                ReceivingTime = m.ReceivingTime
            };

            return(Format(filteredMessagesForFormatting, messageFilteringParams).ToList());
        }
        private static IEnumerable <IMessage> Format(IEnumerable <IMessage> messages, MessageFilteringParams messageFilteringParams)
        {
            var formatedMessages = from m in messages
                                   select FormatMethods.GetFormatMethod(messageFilteringParams.FormattingOptions).Invoke(m);

            return(formatedMessages);
        }