Exemple #1
0
        /// <summary>
        /// Generate PartyList for Task
        /// </summary>
        /// <param name="relatedEntities">Related entities details</param>
        /// <param name="partylist">party list</param>
        /// <param name="service">Organization service</param>
        internal static void GenerateTask(List <Entity> relatedEntities, List <PartyList> partylist, IOrganizationService service)
        {
            // Create task for each related query
            var toUserPartyList = GetToUserPartyList(partylist, relatedEntities[0].LogicalName).ToList <PartyList>();

            foreach (Entity ent in relatedEntities)
            {
                var toUserRelatedPartyList = GetToUserRelatedPartyList(partylist, ent.LogicalName, ent.Id).ToList <PartyList>();
                toUserRelatedPartyList.AddRange(toUserPartyList);
                toUserRelatedPartyList = toUserRelatedPartyList.GroupBy(x => x.PartyId).Select(p => p.First()).ToList <PartyList>();

                foreach (PartyList lst in toUserRelatedPartyList)
                {
                    // create task for each party
                    NotificationActivityHandler.CreateTask(ent, lst, service);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Generate Email and Task both
        /// </summary>
        /// <param name="relatedEntities">list of related entities</param>
        /// <param name="partylist">party list</param>
        /// <param name="globalConfiguration">notification global configuration object</param>
        /// <param name="templateId">Email template unique identifier</param>
        /// <param name="emailTemplateOption">email template option</param>
        /// <param name="service">organization service</param>
        /// <returns>Collection of email objects</returns>
        internal static EntityCollection GenerateEmailAndTask(List <Entity> relatedEntities, List <PartyList> partylist, Dictionary <string, dynamic> globalConfiguration, Guid?templateId, int?emailTemplateOption, IOrganizationService service)
        {
            var toUserPartyList     = GetToUserPartyList(partylist, relatedEntities[0].LogicalName).ToList <PartyList>();
            var carbonCopyPartyList = GetCCPartyList(partylist, relatedEntities[0].LogicalName).ToList <PartyList>();
            var bccPartyList        = GetBCCPartyList(partylist, relatedEntities[0].LogicalName).ToList <PartyList>();

            var toOtherPartyList = GetToOtherPartyList(partylist, relatedEntities[0].LogicalName).ToList <PartyList>();

            // Create Entity Collection to send email in bulk through action calling
            EntityCollection sendEmailList = new EntityCollection();

            sendEmailList.EntityName = "email";

            foreach (Entity ent in relatedEntities)
            {
                // Get Email object using Email Template
                Entity emailObject = GetEmailUsingTemplate(ent, templateId, emailTemplateOption, service);

                var toUserRelatedPartyList = GetToUserRelatedPartyList(partylist, ent.LogicalName, ent.Id).ToList <PartyList>();
                toUserRelatedPartyList.AddRange(toUserPartyList);
                toUserRelatedPartyList = toUserRelatedPartyList.GroupBy(x => x.PartyId).Select(p => p.First()).ToList <PartyList>();

                var carbonCopyRelatedPartyList = GetCCRelatedPartyList(partylist, ent.LogicalName, ent.Id).ToList <PartyList>();
                carbonCopyRelatedPartyList.AddRange(carbonCopyPartyList);
                carbonCopyRelatedPartyList = carbonCopyRelatedPartyList.GroupBy(x => x.PartyId).Select(p => p.First()).ToList <PartyList>();

                var bccRelatedPartyList = GetBCCRelatedPartyList(partylist, ent.LogicalName, ent.Id).ToList <PartyList>();
                bccRelatedPartyList.AddRange(bccPartyList);
                bccRelatedPartyList = bccRelatedPartyList.GroupBy(x => x.PartyId).Select(p => p.First()).ToList <PartyList>();

                var toOtherRelatedPartyList = GetToOtherRelatedPartyList(partylist, ent.LogicalName, ent.Id).ToList <PartyList>();
                toOtherRelatedPartyList.AddRange(toOtherPartyList);
                toOtherRelatedPartyList = toOtherRelatedPartyList.GroupBy(x => x.PartyId).Select(p => p.First()).ToList <PartyList>();

                foreach (PartyList lst in toUserRelatedPartyList)
                {
                    Entity           task  = NotificationActivityHandler.CreateTask(ent, lst, service);
                    List <PartyList> plist = new List <PartyList>();
                    plist.Add(lst);
                    Entity emailEnt = NotificationActivityHandler.CreateEmailInstance(ent, plist, carbonCopyRelatedPartyList, bccRelatedPartyList, task, globalConfiguration, emailObject);
                    sendEmailList.Entities.Add(emailEnt);
                }

                if (toOtherPartyList.Count > 0)
                {
                    Entity emailEnt = NotificationActivityHandler.CreateEmailInstance(ent, toOtherRelatedPartyList, carbonCopyRelatedPartyList, bccRelatedPartyList, null, globalConfiguration, emailObject);
                    sendEmailList.Entities.Add(emailEnt);
                }
            }

            // Call Glocal action SendEmailActivity to send bulk email

            /*if (isSendEmail)
             * {
             *  OrganizationRequest req = new OrganizationRequest("didd_SendEmailActivity");
             *  req["EmailActivities"] = sendEmailList;
             *  service.Execute(req);
             * }*/

            return(sendEmailList);
        }