public ActionResult DeleteConfirmed(int id) { // Check whether i have access to this Lead details var hasAccess = DoIHaveCRMManageAccess(); if (!hasAccess) { return(RedirectToAction("NotAuthorized", "Error", new { area = "" })); } var status = _crmLeadService.Delete(id); if (status) { return(RedirectToAction("Index")); } return(View()); }
public bool Convert(bool createAccount, bool createPotential, int id, int assignedToUserId, int?categoryId, double?expectedAmount, DateTime?expectedCloseDate, string description, DateTime?enquiredOn, int salesStage, int createdByUserId) { var selectedLead = _crmLeadRepository.GetBy(l => l.Id == id, "Person"); if (selectedLead != null) { CRMAccount selectedOrganization = null; if (createAccount) { // Create the Account First var organization = selectedLead.Person.Organization; if (!string.IsNullOrEmpty(organization)) { selectedOrganization = _crmAccountRepository.GetBy(a => a.Title == organization); if (selectedOrganization == null) { selectedOrganization = new CRMAccount { Title = organization, EmployeeCount = EmployeeCount.One2Ten, AssignedToEmployeeId = assignedToUserId, CreatedByUserId = createdByUserId }; _crmAccountRepository.Create(selectedOrganization); _unitOfWork.Commit(); } } } // Create Contact var contact = new CRMContact { PersonId = selectedLead.PersonId, CreatedByUserId = createdByUserId }; // Assign the account Id if (selectedOrganization != null) { contact.ParentAccountId = selectedOrganization.Id; } _crmContactRepository.Create(contact); _unitOfWork.Commit(); if (createPotential) { // Create the Potential var potential = new CRMPotential { CategoryId = categoryId, ExpectedAmount = expectedAmount, ExpectedCloseDate = expectedCloseDate, Description = description, EnquiredOn = enquiredOn, SalesStageId = salesStage, AssignedToUserId = assignedToUserId, ContactId = contact.Id, CreatedByUserId = createdByUserId }; _crmPotentialRepository.Create(potential); _unitOfWork.Commit(); // Move all Lead Technologies to Potential Technologies var technologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == selectedLead.Id).ToList(); foreach (var technology in technologies) { var technologyMap = new CRMPotentialTechnologyMap { PotentialId = potential.Id, TechnologyId = technology.TechnologyId }; _crmPotentialTechnologyMapRepository.Create(technologyMap); } // Move all Lead Activities to Potential Activities var activities = _crmLeadActivityRepository.GetAllBy(m => m.CRMLeadId == selectedLead.Id).ToList(); foreach (var activity in activities) { var potentialActivity = new CRMPotentialActivity { CRMPotentialId = potential.Id, Title = activity.Title, Comment = activity.Comment, CreatedOn = activity.CreatedOn, CreatedByUserId = createdByUserId }; _crmPotentialActivityRepository.Create(potentialActivity); } _unitOfWork.Commit(); } // Delete the Lead _crmLeadService.Delete(id); return(true); } return(false); }