Exemple #1
0
        public static Organisation CreateOrganisation(string Name, string Telephone = "", string Email = "", string Website = "")
        {
            var org = new OrganisationApiController().GetByName(Name);

            if (org == null)
            {
                org = new Organisation();
            }

            org.Name      = Name;
            org.Email     = Email;
            org.Telephone = Telephone;
            org.Website   = Website;

            return(OrganisationDbService.Instance.SaveOrganisation(org));
        }
        // 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);
        }