コード例 #1
0
        public JsonResult ChangeSalesStage(CRMActivityViewModel vm)
        {
            var selectedCRMPotential = _crmPotentialRepository.Get(vm.CRMPotentialId);

            if (selectedCRMPotential != null)
            {
                selectedCRMPotential.SalesStageId    = vm.StatusId.GetValueOrDefault();
                selectedCRMPotential.UpdatedByUserId = WebUser.Id;

                // Send Email Here to Tech Team

                var selectedStatus = _crmSalesStageRepository.Get(vm.StatusId.GetValueOrDefault());
                // Add it as an Activity
                if (selectedStatus != null)
                {
                    var newActivity = new CRMPotentialActivity
                    {
                        Title           = selectedStatus.Name,
                        Comment         = vm.Comment,
                        CRMPotentialId  = selectedCRMPotential.Id,
                        CreatedByUserId = WebUser.Id
                    };

                    _crmPotentialActivityRepository.Create(newActivity);
                }

                _crmPotentialRepository.Update(selectedCRMPotential);
                _unitOfWork.Commit();

                return(Json(true));
            }

            return(Json(false));
        }
コード例 #2
0
        public JsonResult AddNote(CRMActivityViewModel vm)
        {
            var selectedPotential = _crmPotentialRepository.Get(vm.CRMPotentialId);

            if (selectedPotential != null)
            {
                // Add it as an Activity
                var newActivity = new CRMPotentialActivity
                {
                    Title           = vm.Title,
                    Comment         = vm.Comment,
                    CRMPotentialId  = selectedPotential.Id,
                    CreatedByUserId = WebUser.Id
                };

                _crmPotentialActivityRepository.Create(newActivity);
                _unitOfWork.Commit();

                return(Json(true));
            }

            return(Json(false));
        }
コード例 #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);
        }