示例#1
0
        public JsonResult ValidateEmail(string email)
        {
            if (!string.IsNullOrEmpty(email))
            {
                var selectedCRMLead = _crmLeadRepository.GetBy(c => c.Person.Email == email || c.Person.SecondaryEmail == email, "Person");
                if (selectedCRMLead != null)
                {
                    return(Json(new RemoteValidationResult
                    {
                        Status = false,
                        Message = GetCRMLeadDetails(selectedCRMLead)
                    }));
                }

                return(Json(new RemoteValidationResult
                {
                    Status = true,
                    Message = "No Lead Found"
                }));
            }

            return(Json(new RemoteValidationResult
            {
                Status = true,
                Message = "No Lead Found"
            }));
        }
示例#2
0
        public ActionResult Convert(int id)
        {
            var selectedLead = _crmLeadRepository.GetBy(l => l.Id == id, "Person");
            var vm           = new ConvertLeadViewModel();

            if (selectedLead != null)
            {
                vm.LeadId = selectedLead.Id;
                ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", selectedLead.AssignedToUserId);
                vm.Person      = selectedLead.Person;
                vm.Description = selectedLead.Description;
            }

            return(View(vm));
        }
示例#3
0
        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);
        }