예제 #1
0
        public ActionResult Update(CRMPotential potential)
        {
            ApiResult <CRMPotential> apiResult;

            if (ModelState.IsValid)
            {
                if (potential.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        _crmPotentialRepository.Update(potential);
                        _unitOfWork.Commit();
                        return(potential);
                    }, "Potential updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        _crmPotentialRepository.Create(potential);
                        _unitOfWork.Commit();
                        return(potential);
                    }, "Potential created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMPotential>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ActionResult Edit(CRMPotential cRMPotential)
        {
            if (ModelState.IsValid)
            {
                var selectedPotential = _crmPotentialRepository.GetBy(l => l.Id == cRMPotential.Id, "Contact.Person");

                if (selectedPotential != null)
                {
                    selectedPotential.AssignedToUserId  = cRMPotential.AssignedToUserId;
                    selectedPotential.CategoryId        = cRMPotential.CategoryId;
                    selectedPotential.ExpectedAmount    = cRMPotential.ExpectedAmount;
                    selectedPotential.ExpectedCloseDate = cRMPotential.ExpectedCloseDate;
                    selectedPotential.EnquiredOn        = cRMPotential.EnquiredOn;
                    selectedPotential.Description       = cRMPotential.Description;

                    selectedPotential.UpdatedByUserId = WebUser.Id;
                }


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

                return(RedirectToAction("Index"));
            }

            return(View(cRMPotential));
        }
예제 #3
0
        public ActionResult Create(CRMPotential cRMPotential)
        {
            if (ModelState.IsValid)
            {
                cRMPotential.CreatedByUserId = WebUser.Id;

                cRMPotential.Contact.CreatedByUserId = WebUser.Id;

                _crmPotentialRepository.Create(cRMPotential);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(cRMPotential));
        }
 public CRMPotentialDetailsViewModel(CRMPotential potential)
 {
     Id                = potential.Id;
     CategoryId        = potential.CategoryId;
     Category          = potential.Category;
     ExpectedAmount    = potential.ExpectedAmount;
     ExpectedCloseDate = potential.ExpectedCloseDate;
     Description       = potential.Description;
     EnquiredOn        = potential.EnquiredOn;
     SalesStageId      = potential.SalesStageId;
     SalesStage        = potential.SalesStage;
     AssignedToUserId  = potential.AssignedToUserId;
     AssignedToUser    = potential.AssignedToUser;
     ContactId         = potential.ContactId;
     Contact           = potential.Contact;
 }
예제 #5
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);
        }