public static Contact UpdateProperty(this Contact contact, string alias, dynamic value) { var props = contact.GetProperties().ToList(); var prop = props.Where(x => x.alias.ToString().ToLower() == alias.ToLower()).FirstOrDefault(); if (prop == null) { var pipelineConfig = PipelineConfig.GetConfig().AppSettings; var docType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(pipelineConfig.ContactDocTypes); var typeId = docType.PropertyTypes.FirstOrDefault(x => x.Alias.ToLower() == alias.ToLower()).Id; var newProp = new { alias = alias, value = value, id = typeId }; props.Add(newProp); } else { props.Where(x => x.alias.ToString().ToLower() == alias.ToLower()).FirstOrDefault().value = value; } contact.CustomProps = Newtonsoft.Json.JsonConvert.SerializeObject(props); return(contact); }
// method to get config values needed by the UI public Dictionary <string, string> GetConfig() { var settings = PipelineConfig.GetConfig().AppSettings; var config = new Dictionary <string, string>(); config["UseBoard"] = settings.UseBoard ? "true" : "false"; return(config); }
private string TaskRow(Task task) { string notificationEmailRow = PipelineConfig.GetConfig().DigestRow.InnerHtml; string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/umbraco#/pipelineCrm/"; return(notificationEmailRow .Replace("{0}", baseUrl + task.ParentId.ToString()) .Replace("{1}", !string.IsNullOrEmpty(task.Type) ? task.Type + ": " : "") .Replace("{2}", task.Description) .Replace("{3}", "In " + task.ParentName + ", due" + task.DateDue.ToString("dd MMM yyyy"))); }
public PagedSegments GetPagedSegments(int pageNumber, string sortColumn, string sortOrder, string searchTerm, int typeId) { int itemsPerPage = PipelineConfig.GetConfig().AppSettings.PageSize; var items = new List <Segment>(); var SegmentType = typeof(Segment); var query = new Sql().Select("*").From("pipelineSegment"); if (typeId == 0) { query.Append(" where Archived=0 ", typeId); } else if (typeId == -1) { query.Append(" where Archived=1 ", typeId); } else if (typeId == -2) { query.Append(" where TypeId=0 and Archived=0 ", typeId); } else { query.Append(" where TypeId=@0 and Archived=0 ", typeId); } if (!string.IsNullOrEmpty(searchTerm)) { query.Append(" and (Name like @0) ", "%" + searchTerm + "%"); } if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder)) { query.OrderBy(sortColumn + " " + sortOrder); } else { query.OrderBy("Name asc"); } var p = DbService.db().Page <Segment>(pageNumber, itemsPerPage, query); return(new PagedSegments { TotalPages = p.TotalPages, TotalItems = p.TotalItems, ItemsPerPage = p.ItemsPerPage, CurrentPage = p.CurrentPage, Segments = p.Items.ToList() }); }
private string PipelineRow(Pipeline pipeline) { string notificationEmailRow = PipelineConfig.GetConfig().DigestRow.InnerHtml; string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/umbraco#/pipelineCrm/"; if (pipeline.Status == null) { return(""); } return(notificationEmailRow .Replace("{0}", baseUrl + pipeline.Id.ToString()) .Replace("{1}", pipeline.Status.Name + ": ") .Replace("{2}", pipeline.Name) .Replace("{3}", "Created at " + pipeline.DateCreated.ToString("dd MMM yyyy")));; }
public void CreateMember(Contact contact, bool approved = true) { bool createMembers = PipelineConfig.GetConfig().AppSettings.CreateMembers; if (createMembers) { var memberService = UmbracoContext.Application.Services.MemberService; if (memberService.GetByEmail(contact.Email) == null) { var newMember = memberService.CreateMemberWithIdentity(contact.Email, contact.Email, contact.Name, "Member"); newMember.RawPasswordValue = RandomPassword(); newMember.IsApproved = !approved; memberService.Save(newMember); } } }
public static Contact UpdateArrayProperties(this Contact contact, Dictionary <string, string[]> updates) { var props = contact.GetProperties().ToList(); foreach (var update in updates) { var prop = props.Where(x => x.alias.ToString().ToLower() == update.Key.ToLower()).FirstOrDefault(); JArray jValue = JArray.FromObject(update.Value); if (prop == null) { // get doc type from pipeline config string alias = update.Key; var pipelineConfig = PipelineConfig.GetConfig().AppSettings; var docType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(pipelineConfig.ContactDocTypes); if (docType != null) { var type = docType.PropertyTypes.SingleOrDefault(x => x.Alias.ToLower() == alias.ToLower()); if (type != null) { var newProp = new { alias = alias, value = jValue, id = type.Id }; props.Add(newProp); } } } else { prop.value = jValue; } } contact.CustomProps = Newtonsoft.Json.JsonConvert.SerializeObject(props); return(contact); }
protected override TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings) { var ctrl = new PipelineApiController(); var nodes = new TreeNodeCollection(); var mainRoute = "/pipelineCrm/pipelineCrmTree"; bool useBoard = PipelineConfig.GetConfig().AppSettings.UseBoard; var customAreas = GetCustomAreas(); if (id == Constants.System.Root.ToInvariantString()) { nodes.Add( CreateTreeNode( "pipelines", null, queryStrings, GetTranslation("pipeline/opportunities"), "icon-dashboard", true, useBoard ? "/pipelineCrm" : "/pipelineCrm/pipelineCrmTree/browse/0" ) ); nodes.Add( CreateTreeNode( "tasks", null, queryStrings, GetTranslation("pipeline/tasks"), "icon-checkbox", false, mainRoute + "/tasks/0" ) ); nodes.Add( CreateTreeNode( "contacts", null, queryStrings, GetTranslation("pipeline/contacts"), "icon-user", true, mainRoute + "/contacts/0" ) ); nodes.Add( CreateTreeNode( "organisations", "-1", queryStrings, GetTranslation("pipeline/organisations"), "icon-company", true, mainRoute + "/organisations/0" ) ); nodes.Add( CreateTreeNode( "segments", "-1", queryStrings, GetTranslation("pipeline/segments"), "icon-users", true, mainRoute + "/segments/0" ) ); // get custom building blocks foreach (var type in customAreas) { nodes.Add( CreateTreeNode( type.Alias, "-1", queryStrings, type.Name, type.Icon, type.Folders.Any(), mainRoute + "/" + type.Url ) ); } nodes.Add( CreateTreeNode( "recyclebin", null, queryStrings, GetTranslation("general/recycleBin"), "icon-trash", true, "/pipelineCrm/pipelineCrmTree/browse/-1" ) ); nodes.Add( CreateTreeNode( "settings", null, queryStrings, GetTranslation("pipeline/settings"), "icon-settings", false, mainRoute + "/settings/0" ) ); } else if (id == "pipelines") { // list all opp statuses foreach (var status in GetStatuses()) { var newTreeNode = CreateTreeNode( status.Id.ToString() + "_pipelines", id, queryStrings, status.Name, "icon-dashboard", false, "/pipelineCrm/pipelineCrmTree/browse/" + status.Id.ToString()); nodes.Add(newTreeNode); } // get unassigned pipelines var unassigned = ctrl.GetByStatusId(0); nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/unassigned"), "icon-dashboard", false, "/pipelineCrm/pipelineCrmTree/browse/-2" ) ); } else if (id == "organisations") { // list all org types foreach (var type in GetOrgTypes()) { var newTreeNode = CreateTreeNode( type.Id.ToString() + "_organisations", id, queryStrings, type.Name, "icon-company", false, mainRoute + "/organisations/" + type.Id.ToString()); nodes.Add(newTreeNode); } // get unassigned orgs var unassigned = ctrl.GetByStatusId(0); nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/unassigned"), "icon-company", false, mainRoute + "/organisations/-2" ) ); } else if (id == "contacts") { // list all orgs foreach (var type in new ContactTypeApiController().GetAll()) { var newTreeNode = CreateTreeNode( type.Id.ToString() + "_contacts", id, queryStrings, type.Name, "icon-user", false, mainRoute + "/contacts/" + type.Id.ToString()); nodes.Add(newTreeNode); } // get contacts with no groups nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/unassigned"), "icon-user", false, mainRoute + "/contacts/-2" ) ); } // segments else if (id == "segments") { // list all segment types foreach (var type in new SegmentTypeApiController().GetAll()) { var newTreeNode = CreateTreeNode( type.Id.ToString() + "_segments", id, queryStrings, type.Name, "icon-users", false, mainRoute + "/segments/" + type.Id.ToString()); nodes.Add(newTreeNode); } } else if (id == "recyclebin") { // pipelines nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/opportunities"), "icon-dashboard", false, "/pipelineCrm/pipelineCrmTree/browse/-1" ) ); // contacts nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/contacts"), "icon-user", false, mainRoute + "/contacts/-1" ) ); // groups nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/organisations"), "icon-company", false, mainRoute + "/organisations/-1" ) ); nodes.Add( CreateTreeNode( "0", id, queryStrings, GetTranslation("pipeline/segments"), "icon-users", false, mainRoute + "/segments/-1" ) ); } else if (customAreas.Any(x => x.Alias == id)) { var area = customAreas.FirstOrDefault(x => x.Alias == id); // list all orgs foreach (var folder in area.Folders) { var newTreeNode = CreateTreeNode( folder.Url + "_" + area.Alias, id, queryStrings, folder.Name, area.Icon, false, mainRoute + "/" + folder.Url); nodes.Add(newTreeNode); } } return(nodes); //this tree doesn't suport rendering more than 1 level throw new NotSupportedException(); }
public PagedPipelines GetPagedPipelines(int pageNumber, string sortColumn, string sortOrder, string searchTerm, int statusId = 0, int contactId = 0, int organisationId = 0) { int itemsPerPage = PipelineConfig.GetConfig().AppSettings.PageSize; var items = new List <Contact>(); var contactType = typeof(Contact); var query = new Sql().Select("*").From("pipelinePipeline"); if (statusId == 0) { query.Append(" where Archived=0 ", statusId); } else if (statusId == -1) { query.Append(" where Archived=1 ", statusId); } else if (statusId == -2) { query.Append(" where StatusId=0 and Archived=0 ", statusId); } else { query.Append(" where StatusId=@0 and Archived=0 ", statusId); } if (contactId > 0) { query.Append(" and ContactId = @0 ", contactId); } if (organisationId > 0) { query.Append(" and OrganisationId = @0 ", organisationId); } if (!string.IsNullOrEmpty(searchTerm)) { query.Append(" and Name like @0 ", "%" + searchTerm + "%"); } if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder)) { query.OrderBy(sortColumn + " " + sortOrder); } else { query.OrderBy("StatusId, Name, DateUpdated asc"); } var p = DbService.db().Page <Pipeline>(pageNumber, itemsPerPage, query); for (int i = 0; i < p.Items.ToList().Count(); i++) { p.Items[i] = new PipelineApiController().GetLinks(p.Items[i]); } return(new PagedPipelines { TotalPages = p.TotalPages, TotalItems = p.TotalItems, ItemsPerPage = p.ItemsPerPage, CurrentPage = p.CurrentPage, Pipelines = p.Items.ToList() }); }
public PagedContacts GetPagedContacts(int pageNumber, string sortColumn, string sortOrder, string searchTerm, int typeId) { int itemsPerPage = PipelineConfig.GetConfig().AppSettings.PageSize; var items = new List <Contact>(); var contactType = typeof(Contact); var query = new Sql().Select("*").From("pipelineContact"); if (typeId == 0) { query.Append(" where Archived=0 ", typeId); } else if (typeId == -1) { query.Append(" where Archived=1 ", typeId); } else if (typeId == -2) { query.Append(" where TypeId=0 and Archived=0 ", typeId); } else { query.Append(" where TypeId=@0 and Archived=0 ", typeId); } if (!string.IsNullOrEmpty(searchTerm)) { query.Append(" and (Name like @0 or Email like @0) ", "%" + searchTerm + "%"); } if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortOrder) && sortColumn != "OrganisationNames") { query.OrderBy(sortColumn + " " + sortOrder); } else { query.OrderBy("Name asc"); } var p = DbService.db().Page <Contact>(pageNumber, itemsPerPage, query); for (int i = 0; i < p.Items.ToList().Count(); i++) { p.Items[i].Organisations = new OrganisationApiController().GetByIds(p.Items[i].OrganisationIds); p.Items[i].OrganisationNames = p.Items[i].Organisations.Select(x => x.Name).OrderBy(x => x); } // special sorting for organisations if (sortColumn == "OrganisationNames") { p.Items = sortOrder.ToLower() != "desc" ? p.Items.OrderBy(x => x.OrganisationNames.FirstOrDefault()).ToList() : p.Items.OrderByDescending(x => x.OrganisationNames.FirstOrDefault()).ToList(); } return(new PagedContacts { TotalPages = p.TotalPages, TotalItems = p.TotalItems, ItemsPerPage = p.ItemsPerPage, CurrentPage = p.CurrentPage, Contacts = p.Items.ToList() }); }
public IEnumerable <CustomPropertyTab> GetCustomProps(string type = "", string docTypeAlias = "") { var outProps = new List <CustomPropertyTab>(); // we need either param if (string.IsNullOrEmpty(docTypeAlias) && string.IsNullOrEmpty(type)) { return(outProps); } // get doc type from pipeline config if (string.IsNullOrEmpty(docTypeAlias) && !string.IsNullOrEmpty(type)) { var pipelineConfig = PipelineConfig.GetConfig().AppSettings; switch (type) { case "contact": docTypeAlias = pipelineConfig.ContactDocTypes; break; case "organisation": docTypeAlias = pipelineConfig.OrganisationDocTypes; break; case "segment": docTypeAlias = pipelineConfig.SegmentDocTypes; break; default: docTypeAlias = pipelineConfig.OpportunityDocTypes; break; } if (string.IsNullOrEmpty(docTypeAlias) || Services.ContentTypeService.GetContentType(docTypeAlias) == null) { return(outProps); } } // check there is such a doc type if (Services.ContentTypeService.GetContentType(docTypeAlias) == null) { return(outProps); } // construct shadow doc type definition var tabs = Services.ContentTypeService.GetContentType(docTypeAlias).PropertyGroups.OrderBy(x => x.SortOrder); foreach (var tab in tabs) { var tabProps = new CustomPropertyTab() { name = tab.Name.Contains('.') ? tab.Name.Split('.')[1] : tab.Name, items = new List <CustomProperty>() }; var props = tab.PropertyTypes.OrderBy(x => x.SortOrder); if (props.Any()) { foreach (var prop in props) { dynamic config = new ExpandoObject(); var prevalues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(prop.DataTypeDefinitionId).PreValuesAsDictionary; if (prevalues.Any()) { var items = new List <CustomPropertyPreValue>(); foreach (var preval in prevalues) { items.Add(new CustomPropertyPreValue() { id = preval.Value.Id, alias = preval.Key, value = preval.Value.Value }); } config.items = items; // marks as multiPicker if it has min/max number if (items.Any(x => x.alias == "minNumber" || x.alias == "maxNumber")) { config.multiPicker = "1"; } } var newProp = new CustomProperty() { id = prop.Id, alias = prop.Alias, label = prop.Name, description = prop.Description, view = PropertyEditorResolver.Current.GetByAlias(prop.PropertyEditorAlias).ValueEditor.View, config = config }; tabProps.items.Add(newProp); } outProps.Add(tabProps); } } return(outProps); }
public ActionResult SendNotifications(string force = "") { if (force == "true" || (DateTime.Now.Hour == PipelineConfig.GetConfig().AppSettings.DigestTime&& DateTime.Now.DayOfWeek != DayOfWeek.Saturday && DateTime.Now.DayOfWeek != DayOfWeek.Sunday)) { var notifactions = CollectNotifications(); string notificationEmailBody = PipelineConfig.GetConfig().DigestBody.InnerHtml; string sender = PipelineConfig.GetConfig().AppSettings.DigestSender; string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/umbraco#/pipelineCrm/"; foreach (var notification in notifactions) { string subject = PipelineConfig.GetConfig().AppSettings.DigestSubject; string todaysTasks = ""; string reminderTasks = ""; string overdueTasks = ""; string upcomingTasks = ""; string pipelineRows = ""; subject = subject.Replace("{0}", notification.userName).Replace("{1}", DateTime.Now.ToString("dd MMM yyyy")); if (notification.todaysTasks.Any()) { foreach (var task in notification.todaysTasks) { todaysTasks += TaskRow(task); } } else { todaysTasks = "No tasks due today."; } if (notification.reminders.Any()) { foreach (var task in notification.reminders) { reminderTasks += TaskRow(task); } } else { reminderTasks = "No task reminders today."; } if (notification.overdueTasks.Any()) { foreach (var task in notification.overdueTasks) { overdueTasks += TaskRow(task); } } else { overdueTasks = "No overdue tasks."; } if (notification.newPipelines.Any()) { foreach (var pipeline in notification.newPipelines) { pipelineRows += PipelineRow(pipeline); } } else { pipelineRows = "No new pipelines today."; } string emailBody = notificationEmailBody .Replace("{0}", subject) .Replace("{1}", todaysTasks) .Replace("{2}", reminderTasks) .Replace("{3}", overdueTasks) .Replace("{4}", upcomingTasks) .Replace("{5}", pipelineRows); umbraco.library.SendMail( sender, notification.userEmail, subject, emailBody, true ); //return Content(emailBody); } return(Json(notifactions.Count() + " emails sent.", JsonRequestBehavior.AllowGet)); } return(Json("Please wait until the time set in the config.", JsonRequestBehavior.AllowGet)); }