Ejemplo n.º 1
0
        public JsonResult RetrieveMultipleEntities([FromUri] ODataQuery oDataQuery)
        {
            log.Info("Entered RetrieveMultipleEntities ");
            ODataQuery odataQueryObject = GetODataQueryObject(Request, "ODataQuery");

            try
            {
                RetrieveMultipleResponse retrieveMultipleResponse = EntityApiUtils.RetrieveEntities(ServiceProxy,
                                                                                                    odataQueryObject);

                ResultSet resultSet = GetResultSet(retrieveMultipleResponse);
                log.Info("Exiting RetrieveMultipleEntities ");
                return(new JsonResult
                {
                    Data = resultSet,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception e)
            {
                log.Info("Exiting RetrieveMultipleEntities with message ");
                return(new JsonResult
                {
                    Data = e.Message
                });
            }
        }
Ejemplo n.º 2
0
        public JsonResult ContactReassignmentEmail(dynamic data)
        {
            log.Info("DuplicateContactEmailToSupport");

            string    hdcSupportEmail = ConfigurationManager.AppSettings["HDCSupportEmail"];
            ColumnSet columns         = new ColumnSet();

            columns.AddColumns(new string[] { "firstname", "lastname", "emailaddress1", "concap_loggedinuser" });
            Entity duplicateContact = EntityApiUtils.ReadContactByEmail(ServiceProxy, data.duplicateContactEmail.Value, columns);
            Entity rep       = EntityApiUtils.ReadContactById(ServiceProxy, Guid.Parse(data.repId.Value), new ColumnSet(true));
            Entity owningRep = null;

            string contactFirstName = EntityApiUtils.GetStringValue(duplicateContact, "firstname");
            string contactLastName  = EntityApiUtils.GetStringValue(duplicateContact, "lastname");
            string submitedRepName  = EntityApiUtils.GetStringValue(rep, "fullname");
            string owningRepName    = "";
            string repEmail         = EntityApiUtils.GetStringValue(rep, "emailaddress1");

            if (duplicateContact.Contains("concap_loggedinuser"))
            {
                owningRepName = ((EntityReference)duplicateContact["concap_loggedinuser"]).Name;
                owningRep     = EntityApiUtils.ReadContactById(ServiceProxy, ((EntityReference)duplicateContact["concap_loggedinuser"]).Id, new ColumnSet(true));
            }

            string emailDescription = "<p>HDC App Admin,</p>";

            emailDescription += "<p>I am requesting that the contact below gets reassigned to me:</p>";
            emailDescription += "<ul><li>" + contactFirstName + " " + contactLastName + "</li>";
            emailDescription += "<li>" + data.duplicateContactEmail.Value + "</li></ul>";
            emailDescription += "<p>Please contact me for details.</p>";

            emailDescription += "<p><strong>TTI Rep requesting contact reassignment: </strong></p>";
            emailDescription += "<ul><li>" + submitedRepName + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(rep, "store.concap_name") + ", " + EntityApiUtils.GetStringValue(rep, "store.concap_city") + ", " + EntityApiUtils.GetStringValue(rep, "store.concap_stateprovince") + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(rep, "telephone1") + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(rep, "emailaddress1") + "</li></ul>";

            emailDescription += "<p><strong>TTI Rep who owns existing contact: </strong></p>";
            emailDescription += "<ul><li>" + owningRepName + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(owningRep, "store.concap_name") + ", " + EntityApiUtils.GetStringValue(rep, "store.concap_city") + ", " + EntityApiUtils.GetStringValue(rep, "store.concap_stateprovince") + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(owningRep, "telephone1") + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(owningRep, "emailaddress1") + "</li></ul>";

            emailDescription += "<p><strong>TTI Manager of existing contact owner: </strong></p>";
            emailDescription += "<ul><li>" + EntityApiUtils.GetStringValue(owningRep, "manager.concap_name") + "</li>";
            emailDescription += "<li>" + EntityApiUtils.GetStringValue(owningRep, "manager.emailaddress") + "</li></ul>";

            log.Info("Sending reassignment email...");
            var task = SendEmailAsync(repEmail, hdcSupportEmail, repEmail, "HDC Contact Reassignment Request", emailDescription, null);

            return(new JsonResult()
            {
                Data = "An email has been submitted for contact reassignment.  An Administrator will be in contact with you regarding this request"
            });
        }
Ejemplo n.º 3
0
        private void PopulateAllContactsFromFilter(EmailEntity emailEntity, EntityCollection activityPartyBccColl)
        {
            var jArrayToAllFilter    = (JArray)emailEntity.ToAllFilter;
            var jobjToAllFilterArray = jArrayToAllFilter.Children <JObject>();
            var filterConditions     = new List <FilterCondition>();

            foreach (var jobjToAllFilter in jobjToAllFilterArray)
            {
                var attributeName  = getPropertyValue(jobjToAllFilter, "attributeName");
                var attributeValue = getPropertyValue(jobjToAllFilter, "attributeValue");
                var operatorValue  = getPropertyValue(jobjToAllFilter, "operator");
                var attributeType  = getPropertyValue(jobjToAllFilter, "attributeType");
                filterConditions.Add(new FilterCondition()
                {
                    attributeName  = attributeName,
                    attributeValue = attributeValue,
                    attributeType  = attributeType,
                    Operator       = operatorValue
                });
            }

            var odataQueryObject = new ODataQuery()
            {
                Columns          = new string[] { "contactid" },
                EntityName       = "contact",
                FilterConditions = filterConditions
            };

            var retrieveMultipleResponse = EntityApiUtils.RetrieveEntities(ServiceProxy, odataQueryObject);

            foreach (var entity in retrieveMultipleResponse.EntityCollection.Entities)
            {
                foreach (var attribute in entity.Attributes)
                {
                    var toContactId     = (Guid)attribute.Value;
                    var activityPartyTo = new Entity("activityparty");
                    activityPartyTo.Attributes.Add("partyid", new EntityReference("contact", toContactId));
                    activityPartyBccColl.Entities.Add(activityPartyTo);
                }
            }
        }
Ejemplo n.º 4
0
        public JsonResult SendEmail(EmailEntity emailEntity)
        {
            var emailId = Guid.Empty;

            log.Info("Entered SendEmail constructor");
            try
            {
                var activityPartyBccColl = new EntityCollection();
                if (emailEntity.ToAll)
                {
                    log.Info("Send to ALL");
                    PopulateAllContactsFromFilter(emailEntity, activityPartyBccColl);
                }
                else
                {
                    log.Info("Send to specific contacts");
                    activityPartyBccColl = PopulateContactsProvided(emailEntity, activityPartyBccColl);
                }

                var fromQueueId = RetrieveFromQueue(emailEntity);

                var activityPartyFrom = new Entity("activityparty");
                activityPartyFrom.Attributes.Add("partyid", new EntityReference("queue", fromQueueId));

                var activityPartyFromColl = new EntityCollection();
                activityPartyFromColl.Entities.Add(activityPartyFrom);

                var    jobjTemplate  = (JObject)emailEntity.Template;
                string strTemplateId = null;
                if (jobjTemplate != null)
                {
                    strTemplateId = getPropertyValue(jobjTemplate, "Id");
                }

                if (!string.IsNullOrEmpty(strTemplateId))
                {
                    #region With Template

                    log.Info("With email template");
                    int count = 1;
                    foreach (var toContact in activityPartyBccColl.Entities)
                    {
                        log.Info("Contact order :" + count);
                        try
                        {
                            var activityPartyToColl = new EntityCollection();
                            var activityPartyTo     = new Entity("activityparty");
                            var toId = ((EntityReference)toContact["partyid"]).Id;
                            activityPartyTo.Attributes.Add("partyid", new EntityReference("contact", toId));
                            activityPartyToColl.Entities.Add(activityPartyTo);

                            var emailText = emailEntity.EmailText;
                            //MTCCA-174.
                            log.Info("Updating personal notes...");
                            UpdateContactWithPersonalNotes(emailText, emailEntity.EmailSubject, emailEntity.EmailBody, toId);

                            log.Info("creating email with attachment...");
                            Entity createdEmail = CreateEmailWithAttachments(strTemplateId, toContact, activityPartyToColl, activityPartyFromColl);

                            log.Info("Sending email...");
                            emailId = SendEmail(createdEmail);
                            Guid logid = EntityApiUtils.CreateLog(ServiceProxy,
                                                                  new EntityReference("contact", emailEntity.FromUserId),
                                                                  (EntityReference)toContact["partyid"], "Email sent with template.", "Email sent " + emailId);
                        }
                        catch (Exception ex)
                        {
                            log.Error("Error sending email, Count " + count);
                            log.Error(ex);
                            Guid logid = EntityApiUtils.CreateLog(ServiceProxy,
                                                                  new EntityReference("contact", emailEntity.FromUserId),
                                                                  (EntityReference)toContact["partyid"], "Email sent with template.", "Email sent " + emailId);
                            log.Info("CRM Log Id " + logid);
                        }
                        count++;
                    }
                    #endregion
                }
                else
                {
                    #region Without Tempalate
                    try
                    {
                        log.Info("Without email template");
                        var emailCrmEntity = new Entity("email");
                        emailCrmEntity.Attributes.Add("bcc", activityPartyBccColl);
                        emailCrmEntity.Attributes.Add("from", activityPartyFromColl);
                        emailCrmEntity.Attributes.Add("subject", emailEntity.EmailSubject);
                        emailCrmEntity.Attributes.Add("description", "<pre style='margin: 0;'>" + emailEntity.EmailBody + "</pre>");
                        emailCrmEntity.Attributes.Add("directioncode", true);

                        log.Info("creating email...");
                        emailId           = ServiceProxy.Create(emailCrmEntity);
                        emailCrmEntity.Id = emailId;

                        log.Info("Sending email...");
                        emailId = SendEmail(emailCrmEntity);
                    }
                    catch (Exception withoutTempEx)
                    {
                        log.Error("SendEmail without template");
                        log.Error(withoutTempEx.Message);
                        Guid crmlogid = EntityApiUtils.CreateLog(ServiceProxy, new EntityReference("contact", emailEntity.FromUserId), "Error in SendEmail() without template ", withoutTempEx.Message);
                        log.Info("Crm log id " + crmlogid);
                    }
                    #endregion
                }
                log.Info("Exiting SendEmail constructor");
            }
            catch (Exception ex)
            {
                log.Error("Error in SendEmail()");
                log.Error(ex.Message);
                Guid crmlogid = EntityApiUtils.CreateLog(ServiceProxy, "Error in SendEmail() ", ex.Message);
                log.Info("Crm log id " + crmlogid);
            }
            return(new JsonResult()
            {
                Data = emailId
            });
        }