public ActionResult Create(CRMPotentialCategory cRMPotentialCategory)
        {
            if (ModelState.IsValid)
            {
                cRMPotentialCategory.CreatedByUserId = WebUser.Id;

                _crmPotentialCategoryRepository.Create(cRMPotentialCategory);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(cRMPotentialCategory));
        }
        public ActionResult Edit(CRMPotentialCategory cRMPotentialCategory)
        {
            var selectedPotentialCategory = _crmPotentialCategoryRepository.Get(cRMPotentialCategory.Id);

            if (selectedPotentialCategory != null)
            {
                selectedPotentialCategory.Title           = cRMPotentialCategory.Title;
                selectedPotentialCategory.Description     = cRMPotentialCategory.Description;
                selectedPotentialCategory.UpdatedByUserId = WebUser.Id;

                _crmPotentialCategoryRepository.Update(selectedPotentialCategory);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(cRMPotentialCategory));
        }
Example #3
0
        public ActionResult Update(CRMPotentialCategory potentialCategory)
        {
            ApiResult <CRMPotentialCategory> apiResult;

            if (ModelState.IsValid)
            {
                if (potentialCategory.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedPotentialCategory             = _crmPotentialCategoryRepository.Get(potentialCategory.Id);
                        selectedPotentialCategory.Title           = potentialCategory.Title;
                        selectedPotentialCategory.Description     = potentialCategory.Description;
                        selectedPotentialCategory.UpdatedByUserId = WebUser.Id;
                        _crmPotentialCategoryRepository.Update(selectedPotentialCategory);
                        _unitOfWork.Commit();
                        return(selectedPotentialCategory);
                    }, "Potential Category updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newPotentialCategory = new CRMPotentialCategory
                        {
                            Title           = potentialCategory.Title,
                            Description     = potentialCategory.Description,
                            CreatedByUserId = WebUser.Id
                        };
                        _crmPotentialCategoryRepository.Create(newPotentialCategory);
                        _unitOfWork.Commit();
                        return(newPotentialCategory);
                    }, "Potential Category created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMPotentialCategory>();
            }

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