Esempio n. 1
0
        public void AddRelationshipEvents(MailMessageItem item)
        {
            var factory = new DaoFactory(CoreContext.TenantManager.GetCurrentTenant().TenantId, CRMConstants.DatabaseId);
            foreach (var contactEntity in item.LinkedCrmEntityIds)
            {
                switch (contactEntity.Type)
                {
                    case ChainXCrmContactEntity.EntityTypes.Contact:
                        var crmContact = factory.GetContactDao().GetByID(contactEntity.Id);
                        CRMSecurity.DemandAccessTo(crmContact);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Case:
                        var crmCase = factory.GetCasesDao().GetByID(contactEntity.Id);
                        CRMSecurity.DemandAccessTo(crmCase);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Opportunity:
                        var crmOpportunity = factory.GetDealDao().GetByID(contactEntity.Id);
                        CRMSecurity.DemandAccessTo(crmOpportunity);
                        break;
                }

                var fileIds = new List<int>();

                foreach (var attachment in item.Attachments.FindAll(attach => !attach.isEmbedded))
                {
                    using (var file = AttachmentManager.GetAttachmentStream(attachment))
                    {
                        var uploadedFileId = ApiHelper.UploadToCrm(file.FileStream, file.FileName,
                                                                       attachment.contentType, contactEntity);
                        if (uploadedFileId > 0)
                        {
                            fileIds.Add(uploadedFileId);
                        }
                    }
                }

                var contentString = GetHistoryContentJson(item);

                ApiHelper.AddToCrmHistory(item, contactEntity, contentString, fileIds);
            }
        }
        public void LinkChainToCrm(int id_message, int id_tenant, string id_user, List<CrmContactEntity> contact_ids)
        {
            var factory = new DaoFactory(CoreContext.TenantManager.GetCurrentTenant().TenantId, CRMConstants.DatabaseId);
            foreach (var crm_contact_entity in contact_ids)
            {

                switch (crm_contact_entity.Type)
                {
                    case ChainXCrmContactEntity.EntityTypes.Contact:
                        var crm_contact = factory.GetContactDao().GetByID(crm_contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_contact);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Case:
                        var crm_case = factory.GetCasesDao().GetByID(crm_contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_case);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Opportunity:
                        var crm_opportunity = factory.GetDealDao().GetByID(crm_contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_opportunity);
                        break;
                }
            }
            
            using (var db = GetDb())
            {
                var chain_info = GetMessageChainInfo(db, id_tenant, id_user, id_message);
                MarkChainAsCrmLinked(db, chain_info.id, chain_info.mailbox, id_tenant, contact_ids);
                AddChainMailsToCrmHistory(db, chain_info, id_tenant, id_user, contact_ids);
            }
        }
        public void AddRelationshipEvents(MailMessageItem item)
        {
            CoreContext.TenantManager.SetCurrentTenant(TenantId);
            var factory = new DaoFactory(CoreContext.TenantManager.GetCurrentTenant().TenantId, CRMConstants.DatabaseId);
            foreach (var contact_entity in item.LinkedCrmEntityIds)
            {
                switch (contact_entity.Type)
                {
                    case ChainXCrmContactEntity.EntityTypes.Contact:
                        var crm_contact = factory.GetContactDao().GetByID(contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_contact);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Case:
                        var crm_case = factory.GetCasesDao().GetByID(contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_case);
                        break;
                    case ChainXCrmContactEntity.EntityTypes.Opportunity:
                        var crm_opportunity = factory.GetDealDao().GetByID(contact_entity.Id);
                        CRMSecurity.DemandAccessTo(crm_opportunity);
                        break;
                }

                var file_ids = StoreAttachmentsToCrm(item, contact_entity);
                var content_string = GetHistoryContentJson(item);
                AddRelationshipEventWithCrmApi(item, contact_entity, content_string, file_ids);
            }
        }