コード例 #1
0
        public static PersonWrapper ToPersonWrapperQuick(Person person)
        {
            var result = new PersonWrapper(person.ID);

            result.DisplayName = person.GetTitle();
            result.IsPrivate = CRMSecurity.IsPrivate(person);
            result.IsShared = person.ShareType == ShareType.ReadWrite || person.ShareType == ShareType.Read;
            result.ShareType = person.ShareType;

            if (result.IsPrivate)
            {
                result.AccessList = CRMSecurity.GetAccessSubjectTo(person)
                                        .Select(item => EmployeeWraper.Get(item.Key));
            }
            result.Currency = !String.IsNullOrEmpty(person.Currency) ?
                new CurrencyInfoWrapper(CurrencyProvider.Get(person.Currency)) :
                null;

            result.SmallFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, person.ID, false).ToLower();
            result.MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, person.ID, false).ToLower();
            result.IsCompany = false;
            result.CanEdit = CRMSecurity.CanEdit(person);
            //result.CanDelete = CRMSecurity.CanDelete(contact);

            result.CreateBy = EmployeeWraper.Get(person.CreateBy);
            result.Created = (ApiDateTime)person.CreateOn;
            result.About = person.About;
            result.Industry = person.Industry;


            result.FirstName = person.FirstName;
            result.LastName = person.LastName;
            result.Title = person.JobTitle;

            return result;
        }
コード例 #2
0
        public static PersonWrapper ToPersonWrapperQuick(Person person)
        {
            var result = new PersonWrapper(person.ID);

            result.DisplayName = person.GetTitle();
            result.IsPrivate   = CRMSecurity.IsPrivate(person);
            result.IsShared    = person.ShareType == ShareType.ReadWrite || person.ShareType == ShareType.Read;
            result.ShareType   = person.ShareType;

            if (result.IsPrivate)
            {
                result.AccessList = CRMSecurity.GetAccessSubjectTo(person)
                                    .Select(item => EmployeeWraper.Get(item.Key));
            }
            result.Currency = !String.IsNullOrEmpty(person.Currency) ?
                              new CurrencyInfoWrapper(CurrencyProvider.Get(person.Currency)) :
                              null;

            result.SmallFotoUrl  = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, person.ID, false);
            result.MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, person.ID, false);
            result.IsCompany     = false;
            result.CanEdit       = CRMSecurity.CanEdit(person);
            //result.CanDelete = CRMSecurity.CanDelete(contact);

            result.CreateBy = EmployeeWraper.Get(person.CreateBy);
            result.Created  = (ApiDateTime)person.CreateOn;
            result.About    = person.About;
            result.Industry = person.Industry;


            result.FirstName = person.FirstName;
            result.LastName  = person.LastName;
            result.Title     = person.JobTitle;

            return(result);
        }
コード例 #3
0
        private ContactWrapper ToContactWrapper(Contact contact)
        {
            ContactWrapper result;

            var person = contact as Person;
            if (person != null)
            {
                var peopleWrapper = new PersonWrapper(person);
                if (person.CompanyID > 0)
                {
                    peopleWrapper.Company = ToContactBaseWrapper(DaoFactory.GetContactDao().GetByID(person.CompanyID));
                }

                result = peopleWrapper;
            }
            else
            {
                var company = contact as Company;
                if (company != null)
                {
                    result = new CompanyWrapper(company);
                    ((CompanyWrapper)result).PersonsCount = DaoFactory.GetContactDao().GetMembersCount(result.ID);
                }
                else throw new ArgumentException();
            }

            if (contact.StatusID > 0)
            {
                var listItem = DaoFactory.GetListItemDao().GetByID(contact.StatusID);
                if (listItem == null) throw new ItemNotFoundException();

                result.ContactStatus = new ContactStatusBaseWrapper(listItem);
            }

            result.TaskCount = DaoFactory.GetTaskDao().GetTasksCount(contact.ID);
            result.HaveLateTasks = DaoFactory.GetTaskDao().HaveLateTask(contact.ID);

            var contactInfos = new List<ContactInfoWrapper>();
            var addresses = new List<Address>();

            var data = DaoFactory.GetContactInfoDao().GetList(contact.ID, null, null, null);

            foreach (var contactInfo in data)
            {
                if (contactInfo.InfoType == ContactInfoType.Address)
                {
                    addresses.Add(new Address(contactInfo));
                }
                else
                {
                    contactInfos.Add(new ContactInfoWrapper(contactInfo));
                }
            }

            result.Addresses = addresses;
            result.CommonData = contactInfos;

            if (contact is Person)
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao()
                                                .GetEnityFields(EntityType.Person, contact.ID, false)
                                                .ConvertAll(item => new CustomFieldBaseWrapper(item)).ToSmartList();
            }
            else
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao()
                                                .GetEnityFields(EntityType.Company, contact.ID, false)
                                                .ConvertAll(item => new CustomFieldBaseWrapper(item)).ToSmartList();
            }

            return result;
        }
コード例 #4
0
        private IEnumerable<ContactWrapper> ToListContactWrapper(List<Contact> itemList)
        {

            if (itemList.Count == 0) return new List<ContactWrapper>();

            var result = new List<ContactWrapper>();

            var personsIDs = new List<int>();
            var companyIDs = new List<int>();
            var contactIDs = new int[itemList.Count];

            var peopleCompanyIDs = new List<int>();

            var peopleCompanyList = new Dictionary<int, ContactBaseWrapper>();

            for (int index = 0; index < itemList.Count; index++)
            {
                var contact = itemList[index];

                if (contact is Company)
                    companyIDs.Add(contact.ID);
                else if (contact is Person)
                {
                    var person = (Person)contact;

                    personsIDs.Add(contact.ID);

                    if (person.CompanyID > 0)
                        peopleCompanyIDs.Add(person.CompanyID);
                }

                contactIDs[index] = itemList[index].ID;
            }

            if (peopleCompanyIDs.Count > 0)
                peopleCompanyList = DaoFactory.GetContactDao().GetContacts(peopleCompanyIDs.ToArray())
                                   .ToDictionary(item => item.ID,
                                                         ToContactBaseWrapper);

            var companiesMembersCount = DaoFactory.GetContactDao().GetMembersCount(companyIDs.Distinct().ToArray());

            var contactStatusIDs = itemList.Select(item => item.StatusID).Distinct().ToArray();
            var contactInfos = new Dictionary<int, List<ContactInfoWrapper>>();

            var haveLateTask = DaoFactory.GetTaskDao().HaveLateTask(contactIDs);
            var contactStatus = DaoFactory.GetListItemDao().GetItems(contactStatusIDs).ToDictionary(item => item.ID,
                                                                                    item => new ContactStatusBaseWrapper(item));

            var personsCustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Person,
                                                                                    personsIDs.ToArray());

            var companyCustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Company,
                                                                                    companyIDs.ToArray());


            var customFields = personsCustomFields.Union(companyCustomFields).GroupBy(item => item.EntityID).ToDictionary(
                           item => item.Key, item => item.Select(ToCustomFieldBaseWrapper));


            var addresses = new Dictionary<int, List<Address>>();
            var taskCount = DaoFactory.GetTaskDao().GetTasksCount(contactIDs);

            var contactTags = DaoFactory.GetTagDao().GetEntitiesTags(EntityType.Contact);

            DaoFactory.GetContactInfoDao().GetAll(contactIDs).ForEach(
                 item =>
                 {
                     if (item.InfoType == ContactInfoType.Address)
                     {
                         if (!addresses.ContainsKey(item.ContactID))
                             addresses.Add(item.ContactID, new List<Address>
                                                               {
                                                                   new Address(item)
                                                               });
                         else
                             addresses[item.ContactID].Add(new Address(item));
                     }
                     else
                     {
                         if (!contactInfos.ContainsKey(item.ContactID))
                             contactInfos.Add(item.ContactID, new List<ContactInfoWrapper> { new ContactInfoWrapper(item) });
                         else
                             contactInfos[item.ContactID].Add(new ContactInfoWrapper(item));
                     }
                 }
            );

            foreach (var contact in itemList)
            {

                ContactWrapper contactWrapper;

                if (contact is Person)
                {
                    var people = (Person)contact;

                    var peopleWrapper = new PersonWrapper(people);

                    if (people.CompanyID > 0 && peopleCompanyList.ContainsKey(people.CompanyID))
                    {
                        peopleWrapper.Company = peopleCompanyList[people.CompanyID];
                    }

                    contactWrapper = peopleWrapper;

                }
                else if (contact is Company)
                {
                    contactWrapper = new CompanyWrapper((Company)contact);

                    if (companiesMembersCount.ContainsKey(contactWrapper.ID))
                        ((CompanyWrapper)contactWrapper).PersonsCount = companiesMembersCount[contactWrapper.ID];
                }
                else
                    throw new ArgumentException();

                if (contactTags.ContainsKey(contact.ID))
                    contactWrapper.Tags = contactTags[contact.ID];

                if (addresses.ContainsKey(contact.ID))
                    contactWrapper.Addresses = addresses[contact.ID];

                contactWrapper.CommonData = contactInfos.ContainsKey(contact.ID) ? contactInfos[contact.ID] : new List<ContactInfoWrapper>();

                if (contactStatus.ContainsKey(contact.StatusID))
                    contactWrapper.ContactStatus = contactStatus[contact.StatusID];

                contactWrapper.HaveLateTasks = haveLateTask.ContainsKey(contact.ID) && haveLateTask[contact.ID];

                contactWrapper.CustomFields = customFields.ContainsKey(contact.ID) ? customFields[contact.ID] : new List<CustomFieldBaseWrapper>();

                contactWrapper.TaskCount = taskCount.ContainsKey(contact.ID) ? taskCount[contact.ID] : 0;

                result.Add(contactWrapper);
            }

            return result;

        }
コード例 #5
0
        private IEnumerable<ContactWithTaskWrapper> ToSimpleListContactWrapper(IReadOnlyList<Contact> itemList)
        {
            if (itemList.Count == 0) return new List<ContactWithTaskWrapper>();

            var result = new List<ContactWithTaskWrapper>();

            var personsIDs = new List<int>();
            var companyIDs = new List<int>();
            var contactIDs = new int[itemList.Count];

            var peopleCompanyIDs = new List<int>();

            var peopleCompanyList = new Dictionary<int, ContactBaseWrapper>();

            for (int index = 0; index < itemList.Count; index++)
            {
                var contact = itemList[index];

                if (contact is Company)
                    companyIDs.Add(contact.ID);
                else if (contact is Person)
                {
                    var person = (Person)contact;

                    personsIDs.Add(contact.ID);

                    if (person.CompanyID > 0)
                        peopleCompanyIDs.Add(person.CompanyID);
                }

                contactIDs[index] = itemList[index].ID;
            }

            if (peopleCompanyIDs.Count > 0)
                peopleCompanyList = DaoFactory.GetContactDao().GetContacts(peopleCompanyIDs.ToArray())
                                   .ToDictionary(item => item.ID,
                                                         ToContactBaseWrapper);


            var contactInfos = new Dictionary<int, List<ContactInfoWrapper>>();

            var addresses = new Dictionary<int, List<Address>>();

            DaoFactory.GetContactInfoDao().GetAll(contactIDs).ForEach(
                item =>
                {
                    if (item.InfoType == ContactInfoType.Address)
                    {
                        if (!addresses.ContainsKey(item.ContactID))
                            addresses.Add(item.ContactID, new List<Address>
                                                               {
                                                                   new Address(item)
                                                               });
                        else
                            addresses[item.ContactID].Add(new Address(item));
                    }
                    else
                    {
                        if (!contactInfos.ContainsKey(item.ContactID))
                            contactInfos.Add(item.ContactID, new List<ContactInfoWrapper> { new ContactInfoWrapper(item) });
                        else
                            contactInfos[item.ContactID].Add(new ContactInfoWrapper(item));
                    }
                }
           );

            var nearestTasks = DaoFactory.GetTaskDao().GetNearestTask(contactIDs.ToArray());

            IEnumerable<TaskCategoryBaseWrapper> taskCategories = new List<TaskCategoryBaseWrapper>();

            if (nearestTasks.Any())
            {
                taskCategories = DaoFactory.GetListItemDao().GetItems(ListType.TaskCategory).ConvertAll(item => new TaskCategoryBaseWrapper(item));
            }

            foreach (var contact in itemList)
            {
                ContactWrapper contactWrapper;

                if (contact is Person)
                {
                    var people = (Person)contact;

                    var peopleWrapper = new PersonWrapper(people);

                    if (people.CompanyID > 0 && peopleCompanyList.ContainsKey(people.CompanyID))
                    {
                        peopleWrapper.Company = peopleCompanyList[people.CompanyID];
                    }

                    contactWrapper = peopleWrapper;
                }
                else if (contact is Company)
                {
                    contactWrapper = new CompanyWrapper((Company)contact);
                }
                else
                {
                    throw new ArgumentException();
                }


                contactWrapper.CommonData = contactInfos.ContainsKey(contact.ID) ? contactInfos[contact.ID] : new List<ContactInfoWrapper>();

                TaskBaseWrapper taskWrapper = null;

                if (nearestTasks.ContainsKey(contactWrapper.ID))
                {
                    var task = nearestTasks[contactWrapper.ID];
                    taskWrapper = new TaskBaseWrapper(task);

                    if (task.CategoryID > 0)
                        taskWrapper.Category = taskCategories.First(x => x.ID == task.CategoryID);
                }

                result.Add(new ContactWithTaskWrapper
                    {
                        Contact = contactWrapper,
                        Task = taskWrapper
                    });
            }

            return result;
        }
コード例 #6
0
        private ContactWrapper ToContactWrapper(Contact contact)
        {
            ContactWrapper result;

            if (contact is Person)
            {
                var people = (Person)contact;

                var peopleWrapper = new PersonWrapper(people);

                if (people.CompanyID > 0)
                    peopleWrapper.Company = ToContactBaseWrapper(DaoFactory.GetContactDao().GetByID(people.CompanyID));

                result = peopleWrapper;

            }
            else if (contact is Company)
                result = new CompanyWrapper((Company)contact);
            else
                throw new ArgumentException();

            if (contact.StatusID > 0)
                result.ContactType = GetContactTypeByID(contact.StatusID);

            result.TaskCount = DaoFactory.GetTaskDao().GetTasksCount(contact.ID);
            result.HaveLateTasks = DaoFactory.GetTaskDao().HaveLateTask(contact.ID);

            var contactInfos = new List<ContactInfoWrapper>();
            var addresses = new List<Address>();

            var data = DaoFactory.GetContactInfoDao().GetList(contact.ID, null, null, null);

            foreach (var contactInfo in data)
                if (contactInfo.InfoType == ContactInfoType.Address)
                    addresses.Add(new Address(contactInfo));
                else
                    contactInfos.Add(new ContactInfoWrapper(contactInfo));

            result.Addresses = addresses;
            result.CommonData = contactInfos;

            if (contact is Person)
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Person, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();
            else
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Company, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();

            return result;
        }
コード例 #7
0
ファイル: CRMApi.Voip.cs プロジェクト: vipwan/CommunityServer
        public IEnumerable<VoipCallWrapper> GetMissedCalls()
        {
            var voipDao = DaoFactory.GetVoipDao();
            var defaultSmallPhoto = ContactPhotoManager.GetSmallSizePhoto(-1, false);   

            var calls = voipDao.GetMissedCalls(SecurityContext.CurrentAccount.ID).Select(
                r =>
                {
                    ContactWrapper contact;
                    if (r.ContactId != 0)
                    {
                        contact = r.ContactIsCompany
                                      ? (ContactWrapper)new CompanyWrapper(r.ContactId) { DisplayName = r.ContactTitle }
                                      : new PersonWrapper(r.ContactId) { DisplayName = r.ContactTitle };
                        contact.SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany);
                    }
                    else
                    {
                        contact = new PersonWrapper(-1) { SmallFotoUrl = defaultSmallPhoto };
                    }
                    return new VoipCallWrapper(r, contact);
                }).ToList();

            _context.SetDataPaginated();
            _context.SetDataFiltered();
            _context.SetDataSorted();
            _context.TotalCount = calls.Count;

            return calls;
        }
コード例 #8
0
ファイル: CRMApi.Voip.cs プロジェクト: vipwan/CommunityServer
        public IEnumerable<VoipCallWrapper> GetCalls(string callType, ApiDateTime from, ApiDateTime to, Guid? agent, int? client)
        {
            var voipDao = DaoFactory.GetVoipDao();

            var filter = new VoipCallFilter
                {
                    Type = callType,
                    FromDate = from != null ? from.UtcTime : (DateTime?)null,
                    ToDate = to != null ? to.UtcTime.AddDays(1).AddMilliseconds(-1) : (DateTime?)null,
                    Agent = agent,
                    Client = client,
                    SortBy = _context.SortBy,
                    SortOrder = !_context.SortDescending,
                    SearchText = _context.FilterValue,
                    Offset = _context.StartIndex,
                    Max = _context.Count,
                };

            _context.SetDataPaginated();
            _context.SetDataFiltered();
            _context.SetDataSorted();
            _context.TotalCount = voipDao.GetCallsCount(filter);

            var defaultSmallPhoto = ContactPhotoManager.GetSmallSizePhoto(-1, false);            
            var calls = voipDao.GetCalls(filter).Select(
                r =>
                    {
                        ContactWrapper contact;
                        if (r.ContactId != 0)
                        {
                            contact = r.ContactIsCompany
                                          ? (ContactWrapper)new CompanyWrapper(r.ContactId) {DisplayName = r.ContactTitle}
                                          : new PersonWrapper(r.ContactId) {DisplayName = r.ContactTitle};
                            contact.SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany);
                        }
                        else
                        {
                            contact = new PersonWrapper(-1) { SmallFotoUrl = defaultSmallPhoto };
                        }            
                        return new VoipCallWrapper(r, contact);
                    }).ToList();
            return calls;
        }