Exemple #1
0
 /// <summary>
 /// Checks if the specified value is not null
 /// </summary>
 /// <param name="entity">Entity to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator NotNull <TEnt>(TEnt entity, string target, string code = ValidationCodes.NULL_NOT_ALLOWED,
                                 NotificationTargetType targetType       = NotificationTargetType.Entity,
                                 bool handleAsError = true)
     where TEnt : class
 {
     return(Require(entity != null, target, code, targetType, handleAsError: handleAsError));
 }
Exemple #2
0
 /// <summary>
 /// Checks if the specified values mathces with the provided regular expression
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="regexp">Regular expression to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator Matches(string value, Regex regexp, string target,
                          string code        = ValidationCodes.NO_MATCH, NotificationTargetType targetType = NotificationTargetType.Property,
                          bool handleAsError = true)
 {
     return(Require(value == null || regexp.IsMatch(value), target, code, targetType,
                    handleAsError: handleAsError));
 }
        /// <summary>
        /// Send notification abount expire policy
        /// </summary>
        /// <param name="unitOfWork"></param>
        /// <param name="title"></param>
        /// <param name="subjectTitleFirst"></param>
        /// <param name="subjectTitleSecond"></param>
        /// <param name="bodyText"></param>
        /// <param name="policyId"></param>
        /// <param name="recipientUserId"></param>
        /// <returns></returns>
        public async Task <UserNotification> SendNotificationExpirePolicy(
            IUnitOfWork unitOfWork,
            string title,
            string subjectTitleFirst,
            string subjectTitleSecond,
            string bodyText,
            int policyId,
            NotificationTargetType type,
            string recipientUserId
            )
        {
            var notification = await this.SendNotification(
                unitOfWork,
                title,
                subjectTitleFirst,
                subjectTitleSecond,
                bodyText,
                NotificationType.Information,
                type,
                policyId,
                null,
                recipientUserId);

            return(notification);
        }
        /// <summary>
        /// Create notification
        /// </summary>
        /// <param name="unitOfWork"></param>
        /// <param name="title"></param>
        /// <param name="subjectTitleFirst"></param>
        /// <param name="subjectTitleSecond"></param>
        /// <param name="bodyText"></param>
        /// <param name="notificationType"></param>
        /// <param name="targetObjectType"></param>
        /// <param name="targetObjectId"></param>
        /// <param name="targetUrl"></param>
        /// <param name="recipientUserId"></param>
        /// <returns></returns>
        public async Task <UserNotification> SendNotification(
            IUnitOfWork unitOfWork,
            string title,
            string subjectTitleFirst,
            string subjectTitleSecond,
            string bodyText,
            NotificationType notificationType,
            NotificationTargetType targetObjectType,
            int?targetObjectId,
            string targetUrl,
            string recipientUserId
            )
        {
            UserNotification userNotification = new UserNotification();

            userNotification.Title              = title;
            userNotification.SubjectTitleFirst  = subjectTitleFirst;
            userNotification.SubjectTitleSecond = subjectTitleSecond;
            userNotification.Body             = bodyText;
            userNotification.NotificationType = notificationType;
            userNotification.TargetObjectType = targetObjectType;
            userNotification.TargetObjectId   = targetObjectId;
            userNotification.TargetUrl        = targetUrl;
            userNotification.RecipientId      = recipientUserId;
            userNotification.CreatedDate      = DateTime.Now;

            unitOfWork.UserNotificationRepository.Insert(userNotification);

            await unitOfWork.SaveAsync();

            return(userNotification);
        }
Exemple #5
0
 /// <summary>
 /// Checks if the specified string is not longer than specified.
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="maxLength">Maximum length of the string</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator MaxLength(string value, int maxLength, string target,
                            string code        = ValidationCodes.TOO_LONG, NotificationTargetType targetType = NotificationTargetType.Property,
                            bool handleAsError = true)
 {
     return(Require(String.IsNullOrEmpty(value) || value.Length <= maxLength, target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #6
0
 /// <summary>
 /// Checks if the specified string is a valid email address
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator IsEmail(string value, string target,
                          string code = ValidationCodes.INVALID_EMAIL,
                          NotificationTargetType targetType = NotificationTargetType.Property,
                          bool handleAsError = true)
 {
     return(Require(String.IsNullOrEmpty(value) || s_EmailRegex.Match(value).Length > 0, target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #7
0
 /// <summary>
 /// Checks if the specified double value is within the specified range
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="lowerValue">Lower bound of the range</param>
 /// <param name="upperValue">Upper bound of the range</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator IsInRange(double value, double lowerValue, double upperValue, string target,
                            string code = ValidationCodes.OUT_OF_RANGE,
                            NotificationTargetType targetType = NotificationTargetType.Property,
                            bool handleAsError = true)
 {
     return(Require(lowerValue <= value && value <= upperValue, target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #8
0
 /// <summary>
 /// Checks if the specified GUID value is not empty
 /// </summary>
 /// <param name="guid">Date to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator NotNullOrEmpty(Guid?guid, string target,
                                 string code = ValidationCodes.EMPTY_GUID,
                                 NotificationTargetType targetType = NotificationTargetType.Property,
                                 bool handleAsError = true)
 {
     return(Require(guid.HasValue && guid.Value != Guid.Empty, target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #9
0
 /// <summary>
 /// Checks if the specified string value is not null or empty
 /// </summary>
 /// <param name="date">Date to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator IsFutureDate(DateTime date, string target,
                               string code = ValidationCodes.FUTURE_DATE,
                               NotificationTargetType targetType = NotificationTargetType.Property,
                               bool handleAsError = true)
 {
     return(Require(date.ToLocalTime() > DateTime.Now, target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #10
0
 /// <summary>
 /// Checks if the specified string value is not null or empty
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator NotNullOrEmpty(string value, string target,
                                 string code = ValidationCodes.NULL_NOT_ALLOWED,
                                 NotificationTargetType targetType = NotificationTargetType.Property,
                                 bool handleAsError = true)
 {
     return(Require(!String.IsNullOrWhiteSpace(value), target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #11
0
 /// <summary>
 /// Checks if the specified value is in the specified list of values
 /// </summary>
 /// <param name="value">Value to check</param>
 /// <param name="list"></param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator IsInList <T>(T value, IList <T> list, string target,
                               string code = ValidationCodes.NOT_IN_LIST,
                               NotificationTargetType targetType = NotificationTargetType.Property,
                               bool handleAsError = true)
     where T : IComparable <T>
 {
     return(Require(list.Contains(value), target, code, targetType,
                    handleAsError: handleAsError));
 }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="type">Type fo the notification</param>
 /// <param name="code">The predefined code of the notification</param>
 /// <param name="target">The target of the notification</param>
 /// <param name="targetType">The type of the target the notification belongs to</param>
 /// <param name="attributes">A collection describing the attributes of the notification</param>
 /// <param name="exception">Optional exception instance</param>
 public NotificationItem(NotificationType type, string code, string target,
                         NotificationTargetType targetType = NotificationTargetType.Operation,
                         IList <object> attributes         = null,
                         Exception exception = null)
 {
     Type          = type;
     Target        = target;
     TargetType    = targetType;
     Code          = code;
     Attributes    = attributes ?? new List <object>();
     ExceptionText = exception == null ? null : exception.Message;
 }
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="type">Type fo the notification</param>
 /// <param name="code">The predefined code of the notification</param>
 /// <param name="target">The target of the notification</param>
 /// <param name="targetType">The type of the target the notification belongs to</param>
 /// <param name="attributes">A collection describing the attributes of the notification</param>
 /// <param name="exception">Optional exception instance</param>
 public NotificationItem(NotificationType type, string code, string target,
     NotificationTargetType targetType = NotificationTargetType.Operation,
     IList<object> attributes = null,
     Exception exception = null)
 {
     Type = type;
     Target = target;
     TargetType = targetType;
     Code = code;
     Attributes = attributes ?? new List<object>();
     ExceptionText = exception == null ? null : exception.Message;
 }
Exemple #14
0
 public ReturnHookAdded(NotificationTargetType hookTypeIn,
                        string hookAddressIn,
                        bool notifyErrorIn,
                        bool notifyStepIn,
                        bool notifyCompleteIn)
 {
     HookType           = hookTypeIn;
     HookAddress        = hookAddressIn;
     NotifyOnError      = notifyErrorIn;
     NotifyStepComplete = notifyStepIn;
     NotifyOnCompletion = notifyCompleteIn;
 }
Exemple #15
0
 /// <summary>
 /// Checks if the specified validation condition is satisfied
 /// </summary>
 /// <param name="condition">Condition to check</param>
 /// <param name="target">Target entity/property name</param>
 /// <param name="code">Validation error code</param>
 /// <param name="targetType">Validation target type</param>
 /// <param name="attributes">Attributes related to the issue</param>
 /// <param name="exception">Exception instance</param>
 /// <param name="handleAsError">True, if this issue should be handled as an error; otherwise, false</param>
 /// <returns>This object itself, for fluent interface purpose</returns>
 public Validator Require(bool condition, string target, string code = ValidationCodes.VALIDATION_FAILS,
                          NotificationTargetType targetType          = NotificationTargetType.Property,
                          IList <object> attributes = null, Exception exception = null,
                          bool handleAsError        = true)
 {
     if (!condition)
     {
         _notifications.Add(new NotificationItem(
                                handleAsError ? NotificationType.Error : NotificationType.Warning,
                                code,
                                target,
                                targetType,
                                attributes,
                                exception));
     }
     return(this);
 }
        public static string NewPracticeToManager(string rootPath, string services, string providers, string address, string managerName, string repName, string createdByName, string practiceName, string returnUrl, NotificationTargetType targetType, int currentBusinessId, string relativeUrl)
        {
            string HtmlTemplate,
                   templatePath         = templatePath = rootPath + "/Email/NewPracticeToManager.html",
                   NotificationType     = "Practice",
                   logoUrl              = string.Format("{0}/Assets/{1}/Logo_{1}.jpg", ConfigurationManager.AppSettings["PortalUrl"] ?? ConfigurationManager.AppSettings["BaseUrl"] ?? "https://crm.careconnectsystems.com", currentBusinessId),
                   notificationSettings = string.Format("{0}/{1}/{2}", ConfigurationManager.AppSettings["PortalUrl"] ?? ConfigurationManager.AppSettings["BaseUrl"] ?? "https://crm.careconnectsystems.com", relativeUrl, "NotificationSettings");

            switch (targetType)
            {
            case NotificationTargetType.Lead:
                NotificationType = "Lead";
                break;

            case NotificationTargetType.Account:
                NotificationType = "Account";
                break;
            }

            HtmlTemplate = File.ReadAllText(templatePath);
            HtmlTemplate = HttpUtility.HtmlDecode(HtmlTemplate);

            HtmlTemplate = HtmlTemplate.Replace("<%LogoUrl%>", logoUrl);
            HtmlTemplate = HtmlTemplate.Replace("<%NotificationSettings%>", notificationSettings);
            HtmlTemplate = HtmlTemplate.Replace("<%NotificationType%>", NotificationType.ToLower());
            HtmlTemplate = HtmlTemplate.Replace("<%PracticeName%>", practiceName);
            HtmlTemplate = HtmlTemplate.Replace("<%ReturnUrl%>", returnUrl);
            HtmlTemplate = HtmlTemplate.Replace("<%ManagerName%>", managerName);
            HtmlTemplate = HtmlTemplate.Replace("<%RepName%>", repName);
            HtmlTemplate = HtmlTemplate.Replace("<%CreatedByName%>", createdByName);

            string displayAddress = "none";

            if (!string.IsNullOrEmpty(address))
            {
                displayAddress = string.IsNullOrEmpty(address.Replace(" ", "").Replace(",", "")) ? "none" : "table-row";
            }
            HtmlTemplate = HtmlTemplate.Replace("<%DisplayAddress%>", displayAddress);

            HtmlTemplate = HtmlTemplate.Replace("<%Address%>", address);

            string displayProvider = "none";

            if (!string.IsNullOrEmpty(providers))
            {
                displayProvider = string.IsNullOrEmpty(providers.Replace(" ", "").Replace(",", "")) ? "none" : "table-row";
            }
            HtmlTemplate = HtmlTemplate.Replace("<%DisplayProvider%>", displayProvider);

            HtmlTemplate = HtmlTemplate.Replace("<%Providers%>", providers);

            string displayServicer = "none";

            if (!string.IsNullOrEmpty(services))
            {
                displayServicer = string.IsNullOrEmpty(services.Replace(" ", "").Replace(",", "")) ? "none" : "table-row";
            }
            HtmlTemplate = HtmlTemplate.Replace("<%DisplayService%>", displayServicer);

            HtmlTemplate = HtmlTemplate.Replace("<%Services%>", services);
            HtmlTemplate = HtmlTemplate.Replace("<%Year%>", DateTime.UtcNow.Year.ToString());

            return(HtmlTemplate);
        }
        internal async Task Run()
        {
            log.Info("Start Expire Policy Background Job");

            try
            {
                int sentNotifications = 0;
                List <Tuple <string, string, string, string, bool> > autopilotUpdateContacts = new List <Tuple <string, string, string, string, bool> >();

                using (IUnitOfWork unitOfWork = UnitOfWork.Create())
                {
                    var maxExpDate  = DateTime.Now.Date.AddDays(30);
                    var currentDate = DateTime.Now.Date;

                    var policies = unitOfWork.PolicyRepository.GetAll().Where(a => a.Status == PolicyStatus.Confirmed && a.EndDate < maxExpDate)
                                   .Select(a => new
                    {
                        id                     = a.Id,
                        expireDate             = a.EndDate,
                        insurerName            = a.Insurer.Name,
                        title                  = a.Title,
                        subTitle               = a.SubTitle,
                        userId                 = a.CreatedById,
                        userAutopilotContactId = a.CreatedBy.AutopilotContactId,
                        autopilotTrack         = a.CreatedBy.AutopilotTrack,
                        policyType             = a.PolicyType.PolicyGroup.Name + " " + a.PolicyType.PolicyTypeName
                    }).ToList();

                    foreach (var policy in policies)
                    {
                        NotificationTargetType notificationTargetType = NotificationTargetType.None;

                        var expDays = (policy.expireDate.Value.Date - currentDate).Days;

                        string expireDays    = null;
                        string message       = null;
                        string title         = null;
                        string subjectFirst  = string.Format("{0} {1}", policy.title, policy.subTitle);
                        string subjectSecond = string.Format("Insurance expires {0}", expireDays);

                        if (expDays < 0)
                        {
                            notificationTargetType = NotificationTargetType.ExpirePolicyExpired;
                            expireDays             = "today";
                            message       = messageExpired;
                            title         = string.Format("Your {0} {1} {2} Insurance policy has expired", policy.insurerName, policy.title, policy.subTitle);
                            subjectSecond = "Your insurance has expired";
                        }
                        else if (expDays == 0)
                        {
                            notificationTargetType = NotificationTargetType.ExpirePolicyToday;
                            expireDays             = "today";
                            subjectSecond          = string.Format("Insurance expires {0}.", expireDays);
                            message = messageToday;
                            title   = string.Format("Your {0} {1} {2} Insurance policy will need to be renewed today", policy.insurerName, policy.title, policy.subTitle);
                        }
                        else if (expDays <= 10)
                        {
                            notificationTargetType = NotificationTargetType.ExpirePolicy10days;
                            expireDays             = expDays == 1 ? "in 1 day" : string.Format("in {0} days", expDays);
                            message       = messageNdays;
                            subjectSecond = string.Format("Insurance expires {0}.", expireDays);
                            title         = string.Format("Your {0} {1} {2} Insurance policy will need to be renewed before {3:d}", policy.insurerName, policy.title, policy.subTitle, policy.expireDate);
                        }
                        else if (expDays <= 30)
                        {
                            notificationTargetType = NotificationTargetType.ExpirePolicy30days;
                            expireDays             = string.Format("in {0} days", expDays);
                            message       = messageNdays;
                            subjectSecond = string.Format("Insurance expires {0}.", expireDays);
                            title         = string.Format("Your {0} {1} {2} Insurance policy will need to be renewed before {3:d}", policy.insurerName, policy.title, policy.subTitle, policy.expireDate);
                        }
                        else
                        {
                            continue;
                        }

                        var notificationWasSent = unitOfWork.UserNotificationRepository.GetAll().Any(a => a.TargetObjectId != null && a.TargetObjectId.Value == policy.id && a.TargetObjectType == notificationTargetType);

                        if (notificationWasSent == false)
                        {
                            message = message.Replace("{insurerName}", policy.insurerName);
                            message = message.Replace("{policyName}", policy.title + " " + policy.subTitle);
                            message = message.Replace("{expireDays}", expireDays);
                            message = message.Replace("{policyType}", policy.policyType);

                            await NotificationProvider.Instance.SendNotificationExpirePolicy(unitOfWork,
                                                                                             title,
                                                                                             subjectFirst,
                                                                                             subjectSecond,
                                                                                             message,
                                                                                             policy.id,
                                                                                             notificationTargetType,
                                                                                             policy.userId
                                                                                             );

                            string journeyName;
                            switch (notificationTargetType)
                            {
                            case NotificationTargetType.ExpirePolicyToday:
                                journeyName = ConfigurationManager.AppSettings["PolicyExpiryToday"];
                                break;

                            case NotificationTargetType.ExpirePolicy10days:
                                journeyName = ConfigurationManager.AppSettings["PolicyExpire10Days"];
                                break;

                            case NotificationTargetType.ExpirePolicy30days:
                                journeyName = ConfigurationManager.AppSettings["PolicyExpire30Days"];
                                break;

                            case NotificationTargetType.ExpirePolicyExpired:
                                journeyName = ConfigurationManager.AppSettings["PolicyExpired"];
                                break;

                            case NotificationTargetType.Profile:
                            case NotificationTargetType.None:
                            default:
                                throw new NotImplementedException();
                            }


                            Tuple <string, string, string, string, bool> autopilotContactModel = new Tuple <string, string, string, string, bool>(policy.userId, policy.userAutopilotContactId, "TriggerJourney", journeyName, policy.autopilotTrack);

                            autopilotUpdateContacts.Add(autopilotContactModel);


                            //TODO: Kate:  Send email to customer
                            //TODO: Kate:  Update autopilot
                            //policy.userAutopilotContactId

                            sentNotifications++;
                        }
                    }

                    if (autopilotUpdateContacts.Any())
                    {
                        SendAutopilotEvents(autopilotUpdateContacts);
                    }
                }

                log.InfoFormat("End Expire Policy Background Job: Sent Notifications = {0}", sentNotifications);
            }
            catch (Exception e)
            {
                log.Fatal("End Expire Policy Background Job with error:", e);
            }
        }