public ActionResult Convert(int id, LeadType type) { Lead lead = _leadService.GetByID(id); Contact company = new Contact(); if (!string.IsNullOrEmpty(lead.CompanyName)) { //add a company contact company.Type = ContactType.Company; company.CompanyName = lead.CompanyName; company.Email = lead.Email; company.Mobile = lead.Mobile; company.Work = lead.Work; company.Address = lead.Address; company.City = lead.City; company.County = lead.County; company.Postcode = lead.Postcode; company.OwnerID = lead.OwnerID; _contactService.Save(company); } Contact person = new Contact(); if (!string.IsNullOrEmpty(lead.FirstName) && !string.IsNullOrEmpty(lead.LastName)) { //add a person contact person.Type = ContactType.Person; person.CompanyID = lead.CompanyID.HasValue ? lead.CompanyID.Value : company.ID; person.FirstName = lead.FirstName; person.LastName = lead.LastName; person.JobTitle = lead.JobTitle; person.Email = lead.Email; person.Mobile = lead.Mobile; person.Work = lead.Work; person.Address = lead.Address; person.City = lead.City; person.County = lead.County; person.Postcode = lead.Postcode; person.OwnerID = lead.OwnerID; _contactService.Save(person); } Sale sale = new Sale() { Name = lead.FirstName + " " + lead.LastName, JobTitle = company.CompanyName, CreatedDate = DateTime.Now, CompanyID = lead.CompanyID.HasValue ? lead.CompanyID.Value : company.ID, OwnerID = lead.OwnerID, PersonID = person.ID, Status = SaleType.Prospecting, CampaignID = lead.CampaignID }; // set converted date lead.Converted = DateTime.Now; _leadService.Save(lead); _saleService.Save(sale); _activityService.Create("was converted", AreaType.Sale, User.Identity.Name, sale.ID); // re-assign existing tags lead.Tags.ToList().ForEach(t => _saleService.AssignTag(sale, t.Tag)); TempData.Add("StatusMessage", "Lead converted"); return(RedirectToAction("Index", "Sale")); }
public ActionResult Add(Sale sale, FormCollection form, bool?convert) { bool isNew = false; //write activity to the log if (sale.ID == 0) { isNew = true; sale.Status = SaleType.Prospecting; } if (!string.IsNullOrEmpty(form["Companies"])) { sale.CompanyID = Convert.ToInt32(form["Companies"]); } if (!string.IsNullOrEmpty(form["People"])) { sale.PersonID = Convert.ToInt32(form["People"]); } if (!string.IsNullOrEmpty(form["Members"])) { sale.OwnerID = Convert.ToInt32(form["Members"]); } if (!string.IsNullOrEmpty(form["PriorityType"])) { sale.Priority = (PriorityType)Enum.Parse(typeof(CrumbCRM.PriorityType), form["PriorityType"], true); } _saleService.Save(sale); if (!string.IsNullOrEmpty(form["Tags"])) { var current = _tagService.GetByArea(AreaType.Sale); string[] tags = form["Tags"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); tags.ToList().ForEach(t => { var tag = _tagService.GetByName(t); if (tag == null) { tag = new Tag() { Name = t, CreatedDate = DateTime.Now, CreatedByID = _membershipService.GetCurrentMember().UserId }; _tagService.Save(tag); } if (!current.Contains(tag)) { _saleService.AssignTag(sale, tag); } }); } if (isNew) { _activityService.Create("was added", AreaType.Sale, User.Identity.Name, sale.ID); } TempData.Add("StatusMessage", "Sale added"); return(RedirectToAction("Index")); }