Beispiel #1
0
        public GrowCreate.PipelineCRM.Models.Task CreateTouchPoint(string description, int contactId, int pipelineId = 0, string subject = "")
        {
            var taskApi     = new TaskApiController();
            var pipelineApi = new PipelineApiController();

            if (pipelineId == 0)
            {
                var newPipe = new Pipeline();
                newPipe.Name      = subject;
                newPipe.ContactId = contactId;
                newPipe           = pipelineApi.PostSave(newPipe);
                pipelineId        = newPipe.Id;
            }

            var newTask = new GrowCreate.PipelineCRM.Models.Task()
            {
                Description = description,
                ContactId   = contactId,
                UserId      = -1,
                PipelineId  = pipelineId
            };

            newTask = taskApi.PostSave(newTask);
            return(newTask);
        }
Beispiel #2
0
        public Pipeline UpdateOpportunity(int id, string description, double amount = 0, int statusId = 0)
        {
            var pipelineApi = new PipelineApiController();
            var pipeline    = pipelineApi.GetById(id);

            pipeline.Value        = amount;
            pipeline.Name         = description;
            pipeline.StatusId     = statusId;
            pipeline.DateComplete = DateTime.Now;

            return(new PipelineApiController().PostSave(pipeline));
        }
Beispiel #3
0
        public IEnumerable <Pipeline> GetOpportunitiesByContactId(int contactId)
        {
            var pipelineApi = new PipelineApiController();
            var pipelines   = pipelineApi.GetByContactId(contactId).Reverse();

            foreach (var pipeline in pipelines)
            {
                pipeline.Tasks = new TaskApiController().GetByPipeline(pipeline.Id).OrderBy(x => x.DateCreated).Reverse();
            }

            return(pipelines);
        }
        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();
        }
Beispiel #5
0
        // deprecate further down...

        public Pipeline CreateNew(string name, string organisation, string email, string telephone, string subject, string comment, int nodeId = 0, double value = 0, int probability = 50, int statusId = 0, Dictionary <string, dynamic> customProps = null)
        {
            var newPipeline = new Pipeline();

            // we need at least name, email and organisation
            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(email))
            {
                return(newPipeline);
            }

            var taskController     = new TaskApiController();
            var orgController      = new OrganisationApiController();
            var contactController  = new ContactApiController();
            var pipelineController = new PipelineApiController();

            int currentOrgId = 0;

            if (!string.IsNullOrEmpty(organisation))
            {
                // check if we have an org with that email, if not create one
                var currentOrg = orgController.GetByName(organisation);
                if (currentOrg == null)  // organisation is optional
                {
                    currentOrg = orgController.PostSave(new Organisation()
                    {
                        Id          = 0,
                        UserId      = 0,
                        Name        = organisation,
                        DateCreated = DateTime.Now,
                        Email       = email
                    });

                    currentOrgId = currentOrg.Id;
                }
            }

            // check if we have a member with that email, if not create one
            var contact = contactController.GetByEmail(email);

            if (contact == null)
            {
                var newContact = new Contact()
                {
                    Id = 0,
                    OrganisationIds = currentOrgId.ToString(),
                    Name            = name,
                    Telephone       = telephone,
                    Email           = email
                };
                contact = contactController.PostSave(newContact);
            }

            // install cookie for personalised content
            HttpCookie cookie = new HttpCookie("PipelineContactId");

            cookie.Value   = contact.Id.ToString();
            cookie.Expires = DateTime.MaxValue;
            HttpContext.Current.Response.SetCookie(cookie);

            //finally, create a new pipeline and note
            newPipeline = pipelineController.PostSave(new Pipeline()
            {
                Name           = subject,
                DateCreated    = DateTime.Now,
                StatusId       = statusId,
                OrganisationId = currentOrgId,
                ContactId      = contact.Id,
                Value          = value,
                DateComplete   = DateTime.Now,
                Probability    = probability, // todo: read from node
            });

            if (customProps != null)
            {
                newPipeline.UpdateProperties(customProps);
            }


            if (!String.IsNullOrEmpty(comment))
            {
                var newNote = taskController.PostSave(new GrowCreate.PipelineCRM.Models.Task()
                {
                    Description = comment,
                    PipelineId  = newPipeline.Id,
                    UserId      = -1
                });
            }
            return(newPipeline);
        }