Example #1
0
        public ActionResult Update(CRMLeadCategory vm)
        {
            ApiResult <CRMLeadCategory> apiResult;

            if (ModelState.IsValid)
            {
                if (vm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedLeadCategory             = _crmLeadCategoryRepository.Get(vm.Id);
                        selectedLeadCategory.Title           = vm.Title;
                        selectedLeadCategory.Description     = vm.Description;
                        selectedLeadCategory.UpdatedByUserId = WebUser.Id;
                        _crmLeadCategoryRepository.Update(selectedLeadCategory);
                        _unitOfWork.Commit();
                        return(selectedLeadCategory);
                    }, "Lead Category updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newLeadCategory = new CRMLeadCategory
                        {
                            Title           = vm.Title,
                            Description     = vm.Description,
                            CreatedByUserId = WebUser.Id
                        };
                        _crmLeadCategoryRepository.Create(newLeadCategory);
                        _unitOfWork.Commit();
                        return(newLeadCategory);
                    }, "Lead Category created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMLeadCategory>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult Edit(CRMLeadCategory cRMLeadCategory)
        {
            if (ModelState.IsValid)
            {
                var selectedLeadCategory = _crmLeadCategoryRepository.Get(cRMLeadCategory.Id);

                if (selectedLeadCategory != null)
                {
                    selectedLeadCategory.Title           = cRMLeadCategory.Title;
                    selectedLeadCategory.Description     = cRMLeadCategory.Description;
                    selectedLeadCategory.UpdatedByUserId = WebUser.Id;

                    _crmLeadCategoryRepository.Update(selectedLeadCategory);
                    _unitOfWork.Commit();

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

            return(View(cRMLeadCategory));
        }