Example #1
0
        public HttpResponseMessage GetDropdownValue(byte dropdownId)
        {
            GetDropdownValueResponse response = dropdownValuesService.GetDropdownValue(new GetDropdownValueRequest()
            {
                DropdownID = dropdownId, AccountId = 1
            });

            return(Request.BuildResponse(response));
        }
Example #2
0
        public JsonResult GetCommunities(int DropDownID)
        {
            GetDropdownValueRequest req = new GetDropdownValueRequest()
            {
                DropdownID = DropDownID, AccountId = this.Identity.ToAccountID()
            };
            GetDropdownValueResponse resp = dropdownValuesService.GetDropdownValue(req);

            return(Json(resp.DropdownValues.DropdownValuesList.ToArray(), JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult DropdownvaluesView(int dropdownID)
        {
            GetDropdownValueRequest request = new GetDropdownValueRequest();

            request.DropdownID = dropdownID;
            request.AccountId  = this.Identity.ToAccountID();
            GetDropdownValueResponse response = dropdownValuesService.GetDropdownValue(request);

            return(PartialView("_DropdownvaluesHtml", response.DropdownValues));
        }
Example #4
0
        public ActionResult EditDropdown(byte dropdownId)
        {
            GetDropdownValueRequest request = new GetDropdownValueRequest();

            request.DropdownID = dropdownId;
            request.AccountId  = this.Identity.ToAccountID();

            GetDropdownValueResponse response = dropdownValuesService.GetDropdownValue(request);

            ViewBag.IsModal = true;
            var view = PartialView("_EditDropdown", response.DropdownValues);

            return(view);
        }
        public GetDropdownValueResponse GetDropdownValue(GetDropdownValueRequest request)
        {
            GetDropdownValueResponse response = new GetDropdownValueResponse();
            Dropdown dropdown = dropdownRepository.FindBy(request.DropdownID, request.AccountId);

            if (dropdown == null)
            {
                response.Exception = GetDropdownvaluesNotFoundException();
            }
            else
            {
                DropdownViewModel dropdownViewModel = Mapper.Map <Dropdown, DropdownViewModel>(dropdown);
                response.DropdownValues = dropdownViewModel;
            }
            return(response);
        }
        public GetDropdownValueResponse GetDropdownValue(short dropDownValueId)
        {
            GetDropdownValueResponse response = new GetDropdownValueResponse();
            DropdownValue            dropdown = dropdownRepository.GetDropdownValue(dropDownValueId);

            if (dropdown == null)
            {
                response.Exception = GetDropdownvaluesNotFoundException();
            }
            else
            {
                DropdownValueViewModel dropdownViewModel = Mapper.Map <DropdownValue, DropdownValueViewModel>(dropdown);
                response.DropdownValue = dropdownViewModel;
            }
            return(response);
        }
        private void NotifyByEmail(Account accountInfo, List <WebVisitReport> relatedVisits, UserBasicInfo owner, string subject,
                                   GetDropdownValueResponse lifeCycleStages, Dictionary <Guid, string> emailProvider, string to)
        {
            Log.Verbose("Distinct UserId: " + owner.UserID + " distinct User name: " + owner.FirstName + " " + owner.LastName);

            var emailContent = GetEmailContent(owner, relatedVisits, lifeCycleStages);
            var accountName  = relatedVisits.First().AccountName;

            var visitReference = relatedVisits.Select(c => c.VisitReference).FirstOrDefault();

            if (string.IsNullOrEmpty(to) || to == DefaultEmail)
            {
                return;
            }

            var subjectLine = subject + " - " + accountName;

            emailContent = "<div style='font-family:arial,sans-serif;font-size:12px'><label>Account: <strong style='font-family:arial,sans-serif'>  " + accountName
                           + "<br></strong> Account Executive: <strong>" + owner.FullName + "</strong><br><br></label>" + emailContent
                           + (relatedVisits.Any() ? "<div style='font-family:arial,sans-serif;font-size:12px'><label>Above timestamps are according to " + owner.TimeZone + "<br></div>" : "")
                           + "</div>";

            if (!(emailProvider?.Any() ?? false))
            {
                return;
            }

            var fromEmailId  = !string.IsNullOrEmpty(emailProvider.FirstOrDefault().Value) ? emailProvider.FirstOrDefault().Value : "*****@*****.**";
            var emailRequest = new SendMailRequest
            {
                TokenGuid     = emailProvider.FirstOrDefault().Key,
                RequestGuid   = Guid.NewGuid(),
                ScheduledTime = DateTime.UtcNow.NextMinute(),
                Subject       = subjectLine,
                Body          = GenerateEmailBody(emailContent, accountInfo.AccountID),
                To            = new List <string> {
                    to
                },
                IsBodyHtml = true,
                From       = fromEmailId,
                CategoryID = (short)EmailNotificationsCategory.WebVisitInstantNotification,
                AccountID  = accountInfo.AccountID
            };

            _mailService.Send(emailRequest);
            Log.Informational("Successfully sent web visit notification: " + visitReference + ". To user: " + to);
        }
Example #8
0
        public static void Trigger(object stateInfo)
        {
            try
            {
                if (dailySummaryInprogress)
                {
                    return;
                }
                dailySummaryInprogress = true;
                Logger.Current.Verbose("WebVisit DailySummary Processor triggered");

                string includeToday = System.Configuration.ConfigurationManager.AppSettings["INCLUDE_CURRENT_DAY_IN_DAILY_SUMMARY"].ToLower();

                var webAnalyticProviders = accountRepository.GetWebAnalyticsProviders();

                var accounts = webAnalyticProviders.Select(a => a.AccountID);

                var startDate = DateTime.Now.ToUniversalTime().Date.AddDays(-1);
                var endDate   = includeToday == "true" ? DateTime.Now.ToUniversalTime() : DateTime.Now.ToUniversalTime().Date;


                foreach (var accountId in accounts)
                {
                    Logger.Current.Informational("Current Account:", accountId.ToString());

                    var account = accountRepository.GetAccountBasicDetails(accountId);

                    var webAnalyticProvider = webAnalyticProviders.Where(p => p.AccountID == accountId).FirstOrDefault() ?? new WebAnalyticsProvider();

                    var accountInfo = new AccountBasicInfo()
                    {
                        AccountID      = accountId,
                        AccountName    = account.AccountName,
                        TimeZone       = account.TimeZone,
                        WebAnalyticsID = webAnalyticProvider.Id
                    };


                    GetDropdownValueResponse lifeCycleStages = dropdownService.GetDropdownValue(new GetDropdownValueRequest()
                    {
                        AccountId = accountInfo.AccountID, DropdownID = (byte)DropdownFieldTypes.LifeCycle
                    });

                    var emailProviderResponse = communicationService.GetEmailProviders(new GetEmailProvidersRequest()
                    {
                        AccountId = accountInfo.AccountID
                    });
                    if (emailProviderResponse.Exception != null)
                    {
                        throw emailProviderResponse.Exception;
                    }

                    var communicationResponse = communicationService.GetDefaultCampaignEmailProvider(new GetDefaultCampaignEmailProviderRequest()
                    {
                        AccountId = accountInfo.AccountID
                    });
                    var serviceProviderGuids            = emailProviderResponse.ServiceProviderGuids;
                    MailRegistrationDb mailRegistration = mailService.GetVMTADetails(serviceProviderGuids);
                    var    providerDetails      = accountService.GetTransactionalProviderDetails(accountInfo.AccountID);
                    string emailContentToAdmins = string.Empty;
                    try
                    {
                        TimeZoneInfo accountTzInfo = TimeZoneInfo.FindSystemTimeZoneById(accountInfo.TimeZone);
                        startDate = TimeZoneInfo.ConvertTimeFromUtc(startDate, accountTzInfo);
                        endDate   = includeToday == "true" ? endDate : TimeZoneInfo.ConvertTimeFromUtc(endDate, accountTzInfo);

                        Logger.Current.Informational("StartDate After: " + startDate);
                        Logger.Current.Informational("StartDate After: " + endDate);

                        GetWebVisitDailySummaryResponse response = webAnalyticsService.GetWebVisitDailySummary(new GetWebVisitDailySummaryRequest()
                        {
                            AccountId = accountInfo.AccountID, StartDate = startDate, EndDate = endDate
                        });

                        GetUsersOptedWebVisitSummaryEmailResponse users = userService.GetUsersOptedWebVisitSummaryEmail(new GetUsersOptedWebVisitSummaryEmailRequest()
                        {
                            AccountId = accountInfo.AccountID
                        });

                        byte status = accountRepository.GetAccountStatus(accountInfo.AccountID);

                        if (status != (byte)AccountStatus.Suspend)
                        {
                            string emailCopyContent = string.Empty;
                            #region Send Mail To Owner
                            foreach (UserBasicInfo userInfo in users.AllUsers)
                            {
                                Logger.Current.Informational("Sending daily summary email to user: "******". To owner: " + userInfo.Email);
                                try
                                {
                                    List <WebVisitReport> relatedVisits = response.WebVisits.Where(c => c.OwnerID == userInfo.UserID).OrderBy(c => c.VisitedOn).ToList();

                                    string emailContent = GetEmailContent(accountInfo, relatedVisits, lifeCycleStages, userInfo.FirstName + " " + userInfo.LastName);
                                    if (emailContent.Length > 0)
                                    {
                                        emailCopyContent = emailCopyContent + emailContent + "<br><hr>";
                                    }

                                    if (webAnalyticProvider.DailyStatusEmailOpted && emailContent.Length > 0)
                                    {
                                        NotifyByEmail(accountInfo, "SmartTouch Web Visit Daily Summary", providerDetails, userInfo.Email, emailContent);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.Current.Error("Error occured while sending web visit daily summary emails for account user: "******" " + userInfo.Email, ex);
                                }
                            }
                            #endregion

                            #region Send Mail To Opted User
                            //add no owner visits to html
                            List <WebVisitReport> unassignedVisits = response.WebVisits.Where(v => ((v.OwnerID.HasValue) ? v.OwnerID.Value == 1 : v.OwnerID == null)).OrderBy(c => c.VisitedOn).ToList();
                            emailCopyContent += GetEmailContent(accountInfo, unassignedVisits, lifeCycleStages, "Not Assigned");
                            foreach (UserBasicInfo userInfo in users.UsersOpted)
                            {
                                Logger.Current.Informational("ADMIN - Sending daily summary email to user: "******". To owner: " + userInfo.Email);
                                try
                                {
                                    if (emailCopyContent.Length > 0)
                                    {
                                        NotifyByEmail(accountInfo, "SmartTouch Web Visit Daily Summary", providerDetails, userInfo.Email, emailCopyContent + "<br>");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Logger.Current.Error("Error occured while sending Opted User Daily Web Visit Daily Summary email for user: "******" " + userInfo.Email, ex);
                                }
                            }
                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Current.Error("Error occured while sending web visit daily summary emails for account: " + accountInfo, ex);
                    }
                }

                dailySummaryInprogress = false;
                Logger.Current.Informational("Completed processing daily summary emails");
            }
            catch (Exception ex)
            {
                dailySummaryInprogress = false;
                Logger.Current.Error("Error occured while sending web visit daily summary emails", ex);
            }
        }
Example #9
0
        private static string GetEmailContent(AccountBasicInfo accountInfo, List <WebVisitReport> relatedVisits, GetDropdownValueResponse lifeCycleStages, string ownerName)
        {
            string emailContent = string.Empty;

            if (relatedVisits.IsAny())
            {
                emailContent = "<div style='font-family:verdana;font-size:12px'> Account Executive: <strong>" + ownerName + "</strong><br>" + emailContent + "</div><br>";

                relatedVisits.ForEach(c =>
                {
                    TimeZoneInfo tzInfo = TimeZoneInfo.FindSystemTimeZoneById(accountInfo.TimeZone);
                    c.VisitedOn         = TimeZoneInfo.ConvertTimeFromUtc(c.VisitedOn, tzInfo);

                    c.LifecycleStage = lifeCycleStages.DropdownValues.DropdownValuesList.Where(d => d.DropdownValueID == c.LifecycleStageId).Select(d => d.DropdownValue).FirstOrDefault() ?? "";
                    c.Phone          = FormatPhoneNumber(c.Phone);
                });
                emailContent += relatedVisits.GetTable(p => p.FirstName
                                                       , p => p.LastName
                                                       , p => p.Email
                                                       , p => p.Phone
                                                       , p => p.Zip
                                                       , p => p.LifecycleStage
                                                       , p => p.VisitedOn
                                                       , p => p.PageViews
                                                       , p => p.Duration
                                                       , p => p.Page1
                                                       , p => p.Page2
                                                       , p => p.Page3
                                                       , p => p.Source
                                                       , p => p.LeadScore
                                                       , p => p.Location);
            }
            return(emailContent);
        }
Example #10
0
        public static void Trigger(Object stateInfo)
        {
            try
            {
                if (emailNotifierIsProcessing)
                {
                    return;
                }
                emailNotifierIsProcessing = true;
                Logger.Current.Verbose("WebVisitEmailNotifier triggered");


                Logger.Current.Verbose("Getting visits");

                GetCurrentWebVisitNotificationsResponse webVisitsToBeNotified = webAnalyticsService.GetCurrentWebVistNotifications(new GetCurrentWebVisitNotificationsRequest());
                Logger.Current.Informational("WebVisitsToBeNotified Count" + webVisitsToBeNotified.CurrentVisits.Count());

                var accounts = webVisitsToBeNotified.CurrentVisits.Select(c => c.AccountId).ToList().Distinct();

                var emailResults = new List <KeyValuePair <IEnumerable <string>, string> >();
                var failedEmails = new List <KeyValuePair <IEnumerable <string>, string> >();

                foreach (int accountId in accounts)
                {
                    var userIds = webVisitsToBeNotified.CurrentVisits
                                  .Where(c => c.AccountId == accountId)
                                  .Select(c => c.OwnerID).Distinct().ToList();
                    if (userIds.IsAny())
                    {
                        Dictionary <Guid, string> emailProvider   = accountService.GetTransactionalProviderDetails(accountId);
                        GetDropdownValueResponse  lifeCycleStages = dropdownService.GetDropdownValue(new GetDropdownValueRequest()
                        {
                            AccountId = accountId, DropdownID = (byte)DropdownFieldTypes.LifeCycle
                        });

                        IEnumerable <UserBasicInfo> optedUsers
                            = userService.GetUsersOptedInstantWebVisitEmail(new GetUsersOptedInstantWebVisitEmailRequest()
                        {
                            AccountId = accountId
                        }).Users;


                        List <UserBasicInfo> owners = userService.GetUsersByUserIDs(new GetUsersByUserIDsRequest()
                        {
                            UserIDs = userIds
                        }).Users.ToList();
                        //add empty owner
                        var eo = new UserBasicInfo()
                        {
                            UserID = 0,
                            Email  = defaultEmail
                        };
                        if (!owners.Any(f => f.Email == defaultEmail))
                        {
                            owners.Add(eo);
                        }



                        var account = accountRepository.GetAccountBasicDetails(accountId);
                        if (account.Status != (byte)AccountStatus.Suspend)
                        {
                            #region == Send email to each user ==
                            //is account subscribed
                            var providerResponse = accountService.GetAccountWebAnalyticsProviders(new GetWebAnalyticsProvidersRequest()
                            {
                                AccountId = accountId
                            });

                            WebAnalyticsProvider provider = providerResponse.WebAnalyticsProviders.FirstOrDefault();

                            foreach (var owner in owners)
                            {
                                IEnumerable <WebVisitReport> relatedVisits = null;
                                if (owner.Email == defaultEmail)
                                {
                                    relatedVisits   = webVisitsToBeNotified.CurrentVisits.Where(c => c.AccountId == accountId && c.OwnerID == null).OrderByDescending(c => c.VisitedOn).ToList();
                                    owner.FirstName = "Not";
                                    owner.LastName  = "Assigned";
                                    owner.TimeZone  = account.TimeZone;
                                }
                                else
                                {
                                    relatedVisits = webVisitsToBeNotified.CurrentVisits.Where(c => c.AccountId == accountId && c.OwnerID == owner.UserID).OrderByDescending(c => c.VisitedOn).ToList();
                                }

                                if (relatedVisits.IsAny())
                                {
                                    try
                                    {
                                        if (provider.NotificationStatus)
                                        {
                                            //when owner is default user or un assigned, email will not be sent to owner.
                                            NotifyByEmail(accountId, relatedVisits, owner, "SmartTouch Current Web Visit Alert", lifeCycleStages, emailProvider, owner.Email);
                                        }
                                        foreach (var optedUser in optedUsers)
                                        {
                                            try
                                            {
                                                NotifyByEmail(accountId, relatedVisits, owner, "SmartTouch Current Web Visit Alert (Admin)", lifeCycleStages, emailProvider, optedUser.Email);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Data.Clear();
                                                ex.Data.Add("Copy User", optedUser.UserID);
                                                Logger.Current.Error("Unable to send web visit email to user: "******", email: " + optedUser.Email, ex);
                                            }
                                        }
                                        emailResults.Add(new KeyValuePair <IEnumerable <string>, string>(relatedVisits.Select(c => c.VisitReference).ToList(), "Success"));
                                    }
                                    catch (Exception ex)
                                    {
                                        ex.Data.Clear();
                                        ex.Data.Add("Copy User", owner.UserID);
                                        Logger.Current.Error("Unable to send web visit email to user: "******"Failed"));
                                    }
                                }
                            }
                            #endregion
                        }
                        emailResults.AddRange(failedEmails);
                    }
                }

                #region == Update Audits ==
                if (emailResults != null && emailResults.Any())
                {
                    webAnalyticsService.UpdateWebVisitNotifications(new UpdateWebVisitNotificationsRequest()
                    {
                        VisitReferences = emailResults
                    });
                }
                #endregion

                emailNotifierIsProcessing = false;
            }

            catch (Exception ex)
            {
                emailNotifierIsProcessing = false;
                Logger.Current.Error("Exception occured in Email Notifier.", ex);
            }

            finally
            {
                //emailNotifierIsProcessing = false;
            }
        }
Example #11
0
        private static void NotifyByEmail(int accountId, IEnumerable <WebVisitReport> relatedVisits, UserBasicInfo owner, string subject,
                                          GetDropdownValueResponse lifeCycleStages, Dictionary <Guid, string> emailProvider, string to)
        {
            Logger.Current.Verbose("Distinct UserId: " + owner.UserID);
            Logger.Current.Verbose("Distinct User name: " + owner.FirstName + " " + owner.LastName);
            relatedVisits.Each(c =>
            {
                TimeZoneInfo tzInfo = TimeZoneInfo.FindSystemTimeZoneById(owner.TimeZone);
                c.VisitedOnUTZ      = TimeZoneInfo.ConvertTimeFromUtc(c.VisitedOn, tzInfo);
                c.LifecycleStage    = lifeCycleStages.DropdownValues.DropdownValuesList.Where(d => d.DropdownValueID == c.LifecycleStageId).Select(d => d.DropdownValue).FirstOrDefault() ?? "";
            });
            Logger.Current.Verbose("Sending notification email to userId:" + owner.UserID);
            var emailContent = relatedVisits.GetTable(p => p.FirstName
                                                      , p => p.LastName
                                                      , p => p.Email
                                                      , p => p.Phone
                                                      , p => p.Zip
                                                      , p => p.LifecycleStage
                                                      , p => p.VisitedOnUTZ
                                                      , p => p.PageViews
                                                      , p => p.Duration
                                                      , p => p.Page1
                                                      , p => p.Page2
                                                      , p => p.Page3
                                                      , p => p.Source
                                                      , p => p.LeadScore
                                                      , p => p.Location);
            var ownerName   = owner.FirstName + " " + owner.LastName;
            var accountName = relatedVisits.First().AccountName;
            //var accountLabel = "<label style='font-family:arial,sans-serif'>Account: <strong>  " + accountName + " </strong> <br></label>";

            var visitReference = relatedVisits.Select(c => c.VisitReference).FirstOrDefault();

            if (!string.IsNullOrEmpty(to) && to != defaultEmail)
            {
                Logger.Current.Verbose("Sending 1 mail to " + to);
                var subjectLine = subject + " - " + accountName;
                emailContent = "<div style='font-family:arial,sans-serif;font-size:12px'><label>Account: <strong style='font-family:arial,sans-serif'>  " + accountName
                               + "<br></strong> Account Executive: <strong>" + ownerName + "</strong><br><br></label>" + emailContent
                               + ((relatedVisits != null && relatedVisits.Any()) ? "<div style='font-family:arial,sans-serif;font-size:12px'><label>Above timestamps are according to " + owner.TimeZone + "<br></div>" : "")
                               + "</div>";

                SendMailRequest emailRequest = new SendMailRequest();
                if (emailProvider != null && emailProvider.Count > 0)
                {
                    var fromEmailId = !string.IsNullOrEmpty(emailProvider.FirstOrDefault().Value) ? emailProvider.FirstOrDefault().Value : "*****@*****.**";
                    emailRequest.TokenGuid     = emailProvider.FirstOrDefault().Key;
                    emailRequest.RequestGuid   = Guid.NewGuid();
                    emailRequest.ScheduledTime = DateTime.Now.AddMinutes(1).ToUniversalTime();
                    emailRequest.Subject       = subjectLine;
                    emailRequest.Body          = GenerateEmailBody(emailContent, accountId);
                    emailRequest.To            = new List <string>()
                    {
                        to
                    };
                    emailRequest.IsBodyHtml = true;
                    emailRequest.From       = fromEmailId;
                    emailRequest.CategoryID = (short)EmailNotificationsCategory.WebVisitInstantNotification;
                    emailRequest.AccountID  = accountId;
                    var sendMailResponse = mailService.Send(emailRequest);
                }
                Logger.Current.Informational("Successfully sent web visit notification: " + visitReference + ". To user: " + to);
            }
        }
        private string GetEmailContent(UserBasicInfo ownerInfo, List <WebVisitReport> relatedVisits, GetDropdownValueResponse lifeCycleStages)
        {
            var emailContent = string.Empty;

            if (!relatedVisits.IsAny())
            {
                return(emailContent);
            }

            relatedVisits.ForEach(c =>
            {
                c.VisitedOn      = c.VisitedOn.ToTimezone(ownerInfo.TimeZone);
                c.LifecycleStage = lifeCycleStages
                                   .DropdownValues
                                   .DropdownValuesList
                                   .Where(d => d.DropdownValueID == c.LifecycleStageId)
                                   .Select(d => d.DropdownValue)
                                   .FirstOrDefault() ?? "";
            });

            emailContent += relatedVisits.GetTable(
                p => p.FirstName,
                p => p.LastName,
                p => p.Email,
                p => p.Phone,
                p => p.Zip,
                p => p.LifecycleStage,
                p => p.VisitedOn,
                p => p.PageViews,
                p => p.Duration,
                p => p.Page1,
                p => p.Page2,
                p => p.Page3,
                p => p.Source,
                p => p.LeadScore,
                p => p.Location);

            return(emailContent);
        }
Example #13
0
        private string GetEmailContent(Account accountInfo, List <WebVisitReport> relatedVisits, GetDropdownValueResponse lifeCycleStages, string ownerName)
        {
            var emailContent = string.Empty;

            if (!relatedVisits.IsAny())
            {
                return(emailContent);
            }

            emailContent = "<div style='font-family:verdana;font-size:12px'> " +
                           "Account Executive: <strong>" + ownerName + "</strong>" +
                           "<br>" + emailContent + "</div><br>";

            relatedVisits.ForEach(x =>
            {
                x.VisitedOn      = x.VisitedOn.ToTimezone(accountInfo.TimeZone);
                x.LifecycleStage = lifeCycleStages
                                   .DropdownValues
                                   .DropdownValuesList
                                   .Where(d => d.DropdownValueID == x.LifecycleStageId)
                                   .Select(d => d.DropdownValue)
                                   .FirstOrDefault() ?? "";
            });

            emailContent += relatedVisits.GetTable(
                p => p.FirstName,
                p => p.LastName,
                p => p.Email,
                p => p.Phone,
                p => p.Zip,
                p => p.LifecycleStage,
                p => p.VisitedOn,
                p => p.PageViews,
                p => p.Duration,
                p => p.Page1,
                p => p.Page2,
                p => p.Page3,
                p => p.Source,
                p => p.LeadScore,
                p => p.Location);

            return(emailContent);
        }