public ActionResult Create(CRMLeadSource cRMLeadSource)
        {
            if (ModelState.IsValid)
            {
                cRMLeadSource.CreatedByUserId = WebUser.Id;

                _crmLeadSourceRepository.Create(cRMLeadSource);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(cRMLeadSource));
        }
Example #2
0
        public ActionResult Update(CRMLeadSource vm)
        {
            ApiResult <CRMLeadSource> apiResult;

            if (ModelState.IsValid)
            {
                if (vm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedLeadSource             = _crmLeadSourceRepository.Get(vm.Id);
                        selectedLeadSource.Title           = vm.Title;
                        selectedLeadSource.Description     = vm.Description;
                        selectedLeadSource.UpdatedByUserId = WebUser.Id;
                        _crmLeadSourceRepository.Update(selectedLeadSource);
                        _unitOfWork.Commit();
                        return(selectedLeadSource);
                    }, "Lead Source updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newLeadSource = new CRMLeadSource
                        {
                            Title           = vm.Title,
                            Description     = vm.Description,
                            CreatedByUserId = WebUser.Id
                        };
                        _crmLeadSourceRepository.Create(newLeadSource);
                        _unitOfWork.Commit();
                        return(newLeadSource);
                    }, "Lead Source created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMLeadSource>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(CRMLeadSource cRMLeadSource)
        {
            if (ModelState.IsValid)
            {
                var selectedLeadSource = _crmLeadSourceRepository.Get(cRMLeadSource.Id);

                if (selectedLeadSource != null)
                {
                    selectedLeadSource.Title           = cRMLeadSource.Title;
                    selectedLeadSource.Description     = cRMLeadSource.Description;
                    selectedLeadSource.UpdatedByUserId = WebUser.Id;

                    _crmLeadSourceRepository.Update(cRMLeadSource);
                    _unitOfWork.Commit();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(cRMLeadSource));
        }