Пример #1
0
        public JsonResult ChangeCRMLeadStatus(CRMActivityViewModel vm)
        {
            var selectedCRMLead = _crmLeadRepository.Get(vm.CRMLeadId);

            if (selectedCRMLead != null)
            {
                selectedCRMLead.LeadStatusId    = vm.StatusId.GetValueOrDefault();
                selectedCRMLead.UpdatedByUserId = WebUser.Id;

                // Send Email Here to Tech Team

                var selectedStatus = _crmLeadStatusRepository.Get(vm.StatusId.GetValueOrDefault());
                // Add it as an Activity
                if (selectedStatus != null)
                {
                    var newActivity = new CRMLeadActivity
                    {
                        Title           = selectedStatus.Name,
                        Comment         = vm.Comment,
                        CRMLeadId       = selectedCRMLead.Id,
                        CreatedByUserId = WebUser.Id
                    };

                    _crmLeadActivityRepository.Create(newActivity);
                }

                _crmLeadRepository.Update(selectedCRMLead);
                _unitOfWork.Commit();
                return(Json(true));
            }

            return(Json(false));
        }
Пример #2
0
        public ActionResult Update(CRMLead crmLead)
        {
            ApiResult <CRMLead> apiResult;

            if (ModelState.IsValid)
            {
                if (crmLead.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        _crmLeadRepository.Update(crmLead);
                        _unitOfWork.Commit();
                        return(crmLead);
                    }, "Lead updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        _crmLeadRepository.Create(crmLead);
                        _unitOfWork.Commit();
                        return(crmLead);
                    }, "Lead created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMLead>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }