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); }
// 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); }