Пример #1
0
        public List <dtoModuleRecipientMessage> GetRecipientsForMessage(long idMessage, String unknownUser, String anonymousUser, ModuleObject obj, lm.Comol.Core.BaseModules.MailSender.dtoUsersByMessageFilters filter, lm.Comol.Core.BaseModules.ProfileManagement.Business.ProfileManagementService pService, Boolean loadAllInfo = true)
        {
            List <dtoModuleRecipientMessage> items = new List <dtoModuleRecipientMessage>();

            try
            {
                List <MailRecipient> mRecipients = GetRecipientsQuery(filter.IdCommunity, false, obj, "", 0, idMessage).ToList();
                if (mRecipients.Any())
                {
                    items = GetParsedMessageRecipients(obj, mRecipients);
                    List <Int32> idUsers = items.Where(r => r.IsInternal).Select(r => r.IdPerson).Distinct().ToList();

                    if (idUsers.Any())
                    {
                        List <Person> users = new List <Person>();
                        if (idUsers.Count <= maxItemsForQuery)
                        {
                            users.AddRange((from p in Manager.GetIQ <Person>() where idUsers.Contains(p.Id) select p).ToList());
                        }
                        else
                        {
                            Int32        pageIndex    = 0;
                            List <Int32> idPagedUsers = idUsers.Skip(pageIndex * maxItemsForQuery).Take(maxItemsForQuery).ToList();
                            while (idPagedUsers.Any())
                            {
                                users.AddRange((from p in Manager.GetIQ <Person>() where idPagedUsers.Contains(p.Id) select p).ToList());
                                pageIndex++;
                                idPagedUsers = idUsers.Skip(pageIndex * maxItemsForQuery).Take(maxItemsForQuery).ToList();
                            }
                        }
                        items.Where(r => r.IsInternal).ToList().ForEach(i => i.UpdatePersonInfo(users.Where(u => u.Id == i.IdPerson).FirstOrDefault(), unknownUser));
                    }
                    if (filter.IdCommunity > 0 && items.Any())
                    {
                        idUsers = items.Select(i => i.IdPerson).ToList();
                        List <LazySubscription> subscriptions = (idUsers.Count <= maxItemsForQuery) ? (from s in Manager.GetIQ <LazySubscription>() where s.IdCommunity == filter.IdCommunity && idUsers.Contains(s.IdPerson) select s).ToList() : (from s in Manager.GetIQ <LazySubscription>() where s.IdCommunity == filter.IdCommunity select s).ToList().Where(s => idUsers.Contains(s.IdPerson)).ToList();
                        items.Where(i => i.IdPerson > 0).ToList().ForEach(i => i.IdRole = subscriptions.Where(s => s.IdPerson == i.IdPerson).Select(s => s.IdRole).FirstOrDefault());
                    }
                    var query = (from r in items
                                 where (filter.IdProfileType < 1 || (filter.IdProfileType > 0 && r.IdProfileType == filter.IdProfileType)) &&
                                 (filter.IdRole < 1 || (filter.IdRole > 0 && r.IdRole == filter.IdRole))
                                 select r);


                    if (filter.IdAgency == -3)
                    {
                        query = query.Where(r => r.IdProfileType != (int)UserTypeStandard.Employee && (filter.IdProfileType <= 0 || filter.IdProfileType == r.IdProfileType));
                    }
                    else
                    {
                        Dictionary <long, List <Int32> > agencyInfos = pService.GetUsersWithAgencies(query.Where(r => r.IsInternal).Select(r => r.IdPerson).ToList().Distinct().ToList());
                        if (filter.IdAgency == -2)
                        {
                            query = query.Where(r => r.IdProfileType == (int)UserTypeStandard.Employee);
                        }
                        else if (agencyInfos.ContainsKey(filter.IdAgency))
                        {
                            query = query.Where(r => r.IdProfileType == (int)UserTypeStandard.Employee && agencyInfos[filter.IdAgency].Contains(r.IdPerson));
                        }
                        else if (filter.IdAgency > 0)
                        {
                            query = query.Where(r => 1 == 2);
                        }
                        if (loadAllInfo || filter.OrderBy == MailSender.UserByMessagesOrder.ByAgency)
                        {
                            Dictionary <long, String> agencyName = pService.GetAgenciesName(agencyInfos.Keys.ToList());
                            foreach (var i in agencyInfos)
                            {
                                query.Where(r => r.IsInternal && i.Value.Contains(r.IdPerson)).ToList().ForEach(r => r.UpdateAgencyInfo(i.Key, (agencyName.ContainsKey(i.Key) ? agencyName[i.Key] : "")));
                            }
                        }
                    }
                    items = query.ToList();
                    items.Where(i => String.IsNullOrEmpty(i.DisplayName) && !String.IsNullOrEmpty(i.Name) && !String.IsNullOrEmpty(i.Surname)).ToList().ForEach(r => r.DisplayName = r.Surname + " " + r.Name);
                    items.Where(i => String.IsNullOrEmpty(i.DisplayName) && String.IsNullOrEmpty(i.Name) && String.IsNullOrEmpty(i.Surname)).ToList().ForEach(r => r.DisplayName   = r.MailAddress);
                }
            }
            catch (Exception ex)
            {
            }
            return(items);
        }
Пример #2
0
        public List <dtoModuleRecipientMessage> GetParsedUsersForMessage(List <dtoModuleRecipientMessage> recipients, lm.Comol.Core.BaseModules.MailSender.dtoUsersByMessageFilters filter, lm.Comol.Core.BaseModules.ProfileManagement.Business.ProfileManagementService pService)
        {
            var query = (from r in recipients select r);

            if (!string.IsNullOrEmpty(filter.Value) && string.IsNullOrEmpty(filter.Value.Trim()) == false)
            {
                switch (filter.SearchBy)
                {
                case Core.BaseModules.ProfileManagement.SearchProfilesBy.Contains:
                    List <String> values = filter.Value.Split(' ').ToList().Where(f => !String.IsNullOrEmpty(f)).Select(f => f.ToLower()).ToList();
                    if (values.Any() && values.Count == 1)
                    {
                        query = query.Where(r => !String.IsNullOrEmpty(r.DisplayName) && r.DisplayName.ToLower().Contains(filter.Value.ToLower()));
                    }
                    else if (values.Any() && values.Count > 1)
                    {
                        // values.Any(r.Name.ToLower().Contains) && values.Any(r.Surname.ToLower().Contains) ||
                        query = query.Where(r => (!String.IsNullOrEmpty(r.Name) && values.Any(r.Name.ToLower().Contains)) || (!String.IsNullOrEmpty(r.Surname) && values.Any(r.Surname.ToLower().Contains)) || values.Any(r.MailAddress.ToLower().Contains) || values.Any(r.DisplayName.ToLower().Contains));
                    }
                    break;

                case Core.BaseModules.ProfileManagement.SearchProfilesBy.Mail:
                    query = query.Where(r => r.MailAddress.ToLower().Contains(filter.Value.ToLower()));
                    break;

                case Core.BaseModules.ProfileManagement.SearchProfilesBy.Name:
                    query = query.Where(r => !String.IsNullOrEmpty(r.Name) && r.Name.ToLower().StartsWith(filter.Value.ToLower()));
                    break;

                case Core.BaseModules.ProfileManagement.SearchProfilesBy.Surname:
                    query = query.Where(r => !String.IsNullOrEmpty(r.Name) && r.Surname.ToLower().StartsWith(filter.Value.ToLower()));
                    break;
                }
            }
            if ((filter.SearchBy == Core.BaseModules.ProfileManagement.SearchProfilesBy.Name || filter.SearchBy == Core.BaseModules.ProfileManagement.SearchProfilesBy.All || filter.SearchBy == Core.BaseModules.ProfileManagement.SearchProfilesBy.Contains || string.IsNullOrEmpty(filter.Value)) && !string.IsNullOrEmpty(filter.StartWith))
            {
                if (filter.StartWith != "#")
                {
                    query = query.Where(r => r.FirstLetter == filter.StartWith.ToLower());
                }
                else
                {
                    query = query.Where(r => pService.DefaultOtherChars().Contains(r.FirstLetter));
                }
            }
            switch (filter.OrderBy)
            {
            case MailSender.UserByMessagesOrder.ByProfileType:
                if (filter.Ascending)
                {
                    query = query.OrderBy(r => filter.ProfyleTypeTranslations[r.IdProfileType]);
                }
                else
                {
                    query = query.OrderByDescending(r => filter.ProfyleTypeTranslations[r.IdProfileType]);
                }
                break;

            case MailSender.UserByMessagesOrder.ByRole:
                if (filter.Ascending)
                {
                    query = query.OrderBy(r => filter.RoleTranslations[r.IdRole]);
                }
                else
                {
                    query = query.OrderByDescending(r => filter.RoleTranslations[r.IdRole]);
                }
                break;

            case MailSender.UserByMessagesOrder.ByInternal:
                if (filter.Ascending)
                {
                    query = query.OrderByDescending(r => r.IsInternal).ThenBy(r => r.DisplayName);
                }
                else
                {
                    query = query.OrderBy(r => r.IsInternal).ThenBy(r => r.DisplayName);
                }
                break;

            case MailSender.UserByMessagesOrder.ByUser:
                if (filter.Ascending)
                {
                    query = query.OrderBy(r => r.DisplayName);
                }
                else
                {
                    query = query.OrderByDescending(r => r.DisplayName);
                }
                break;

            case MailSender.UserByMessagesOrder.ByAgency:
                if (filter.Ascending)
                {
                    query = query.OrderBy(r => r.AgencyName);
                }
                else
                {
                    query = query.OrderByDescending(r => r.AgencyName);
                }
                break;
            }

            return(query.ToList());
        }
Пример #3
0
        public List <dtoFilteredDisplayMessage> ParseObjectMessages(List <dtoFilteredDisplayMessage> messages, String searchBy, String startWith, MessageOrder orderBy, Boolean ascending, lm.Comol.Core.BaseModules.ProfileManagement.Business.ProfileManagementService pService)
        {
            var query = (from m in messages select m);

            if (!string.IsNullOrEmpty(searchBy) && string.IsNullOrEmpty(searchBy.Trim()) == false)
            {
                List <String> values = searchBy.Split(' ').ToList().Where(f => !String.IsNullOrEmpty(f)).Select(f => f.ToLower()).ToList();
                if (values.Any() && values.Count == 1)
                {
                    query = query.Where(r => !String.IsNullOrEmpty(r.DisplayName) && r.DisplayName.ToLower().Contains(searchBy.ToLower()));
                }
                else if (values.Any() && values.Count > 1)
                {
                    // values.Any(r.Name.ToLower().Contains) && values.Any(r.Surname.ToLower().Contains) ||
                    query = query.Where(r => !String.IsNullOrEmpty(r.DisplayName) && values.Any(r.DisplayName.ToLower().Contains));
                }
            }
            if (!String.IsNullOrEmpty(startWith))
            {
                if (startWith != "#")
                {
                    query = query.Where(r => r.FirstLetter == startWith.ToLower());
                }
                else
                {
                    query = query.Where(r => pService.DefaultOtherChars().Contains(r.FirstLetter));
                }
            }
            switch (orderBy)
            {
            case MessageOrder.ByDate:
                if (ascending)
                {
                    query = query.OrderBy(m => m.CreatedOn);
                }
                else
                {
                    query = query.OrderByDescending(m => m.CreatedOn);
                }
                break;

            case  MessageOrder.ByName:
                if (ascending)
                {
                    query = query.OrderBy(m => m.DisplayName);
                }
                else
                {
                    query = query.OrderByDescending(m => m.DisplayName);
                }
                break;
            }

            return(query.ToList());
        }