Ejemplo n.º 1
0
        public string GetDefinition(int contactId, string userId)
        {
            var contactNotificationToSend = contactRepository.Where(c => c.Id == contactId)
                                            .Include(l => l.Client);


            if (!contactNotificationToSend.Any())
            {
                throw new Exception("No contact information found");
            }

            var contact  = contactNotificationToSend.Single();
            var url      = accessTokenProvider.GenerateAccessUrl(userId, "/report/" + contact.Client.Id + "/contact/" + contact.Id);
            var shortUrl = urlShortner.GetShortUrl(url);
            var smsText  = "Du har fått en ny Helloykontakt! Rejta eller dela " + shortUrl;

            return(smsText);
        }
        private ContactDetails GetContactDetails(string userId, Contact contact)
        {
            var contactDefenition = new ContactDetails();

            if (contact.LeadType == "Phone")
            {
                var callerNumberProperty = contact.Property.SingleOrDefault(lp => lp.Type == "CallerNumber" && lp.ContactId == contact.Id);
                if (callerNumberProperty != null)
                {
                    contactDefenition.From =
                        callerNumberProperty.Value;
                }
                var durationProperty = contact.Property.SingleOrDefault(lp => lp.Type == "Duration" && lp.ContactId == contact.Id);
                if (durationProperty != null)
                {
                    var duration = durationProperty.Value;
                    if (!string.IsNullOrEmpty(duration))
                    {
                        contactDefenition.SubjectOrDuration = TimeSpan.FromSeconds(int.Parse(duration)).Minutes + ":" +
                                                              TimeSpan.FromSeconds(int.Parse(duration)).Seconds;
                    }
                    else
                    {
                        contactDefenition.SubjectOrDuration = "0:0";
                    }
                }
            }
            else if (contact.LeadType == "Email")
            {
                var fromEmailProperty = contact.Property.SingleOrDefault(lp => lp.Type == "FromEmail" && lp.ContactId == contact.Id);
                if (fromEmailProperty != null)
                {
                    contactDefenition.From =
                        fromEmailProperty.Value;
                }
                var subjectProperty = contact.Property.SingleOrDefault(lp => lp.Type == "Subject" && lp.ContactId == contact.Id);
                if (subjectProperty != null)
                {
                    var subject = subjectProperty.Value;
                    contactDefenition.SubjectOrDuration = subject;
                }
            }
            else if (contact.LeadType == "Chat")
            {
                var fromValues    = new List <string>();
                var phoneProperty = contact.Property.SingleOrDefault(lp => lp.Type == "Phone" && lp.ContactId == contact.Id);
                if (phoneProperty != null)
                {
                    fromValues.Add(phoneProperty.Value);
                }
                var emailProperty = contact.Property.SingleOrDefault(lp => lp.Type == "Email" && lp.ContactId == contact.Id);
                if (emailProperty != null)
                {
                    fromValues.Add(emailProperty.Value);
                }

                contactDefenition.From = string.Join(", ", fromValues);
            }

            contactDefenition.InsideUrl = accessTokenProvider.GenerateAccessUrl(userId,
                                                                                "/report/" + contact.ClientId + "/contact/" + contact.Id);
            contactDefenition.Date = contact.Date.ToString("yyyy-MM-dd HH:mm");
            return(contactDefenition);
        }