예제 #1
0
        /// <summary>
        /// Returns the string data that should be replaced into the template text
        /// to create the final letter for the students.
        /// </summary>
        /// <param name="parameter">The parameter name.</param>
        /// <returns>Value that should replace the parameter</returns>
        private string replaceParameter(string parameter, NotificationGeneratorHelper helper)
        {
            // Trim the {}
            int length = parameter.Length;

            parameter = parameter.Substring(1, length - 2);

            // replace the value
            switch (parameter.ToLower())
            {
            case "badgename":
                return(string.IsNullOrWhiteSpace(helper.BadgeName) ? helper.FirstName : helper.BadgeName);

            case "firstname":
                return(helper.FirmName);

            case "fullname":
                return(helper.FullName);

            case "seminarbegindate":
                return(helper.SeminarBegin);

            case "seminarenddate":
                return(helper.SeminarEnd);

            case "seminardeadline":
                return(helper.SeminarDeadline);

            case "title":
                return(helper.Title);

            case "firmname":
                return(helper.FirmName);

            case "username":
                return(helper.UserName);

            case "password":

                return(helper.Password ?? _membershipService.ResetPasswordNoEmail(helper.UserName));

                //var password = _membershipService.ResetPasswordNoEmail(helper.UserName);
                ///return password;
            }

            throw new ArgumentException("Invalid parameter was passed.");
        }
예제 #2
0
        public string GenerateNotification(string template, Person person, string siteId, int?seminarId = null, Invitation invitation = null, string password = null)
        {
            Seminar seminar;

            if (seminarId.HasValue)
            {
                seminar = _seminarRepository.GetNullableById(seminarId.Value);
            }
            else
            {
                seminar = SiteService.GetLatestSeminar(siteId);
            }

            var helper = new NotificationGeneratorHelper(person, seminar, siteId, invitation, password);

            return(HandleBody(template, helper));
        }
예제 #3
0
        /// <summary>
        /// Takes the template text from the database and converts it to the finalized text
        /// </summary>
        /// <param name="body">Template text from the db</param>
        /// <returns>Completed text ready for exporting</returns>
        private string HandleBody(string body, NotificationGeneratorHelper helper)
        {
            Check.Require(helper != null, "helper is required.");

            // Begin actual processing function
            string tempbody = "";
            string parameter;

            // Find the beginning of a replacement string
            int begindex = body.IndexOf("{");
            int endindex;

            while (begindex >= 0)
            {
                // Copy the text that comes before the replacement string to temp
                tempbody = tempbody + body.Substring(0, begindex);
                // Removes the first part from the string before the {
                body = body.Substring(begindex);

                // Find the end of a replacement string
                endindex = body.IndexOf("}");

                // Pulls the text between {}
                parameter = body.Substring(0, endindex + 1);
                // removes the parameter substring
                body = body.Substring(endindex + 1);

                tempbody = tempbody + replaceParameter(parameter, helper);

                // Find the beginning of a replacement string
                begindex = body.IndexOf("{");
            }

            // Gets the remaining text from the template after the last tag
            tempbody = tempbody + body;

            return(tempbody);
        }