/// <summary>
        /// Валидация преди запис на резултат
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private string IsValidResult(CaseSessionResultEditVM model)
        {
            if (model.SessionResultId < 0)
            {
                return("Няма избран резултат");
            }

            var selectListItems = nomService.GetDDL_SessionResultBase(model.SessionResultId);

            if (selectListItems.Count > 1)
            {
                if (model.SessionResultBaseId < 1)
                {
                    return("Няма избрано основание");
                }
            }

            if (model.IsMain)
            {
                if (service.IsExistMainResult(model.CaseSessionId, model.Id))
                {
                    return("Вече има избран основен резултат");
                }
            }

            return(string.Empty);
        }
        public IActionResult EditResult(CaseSessionResultEditVM model)
        {
            SetViewbagResult(model.CaseSessionId);
            if (!ModelState.IsValid)
            {
                return(View(nameof(Edit), model));
            }

            string _isvalid = IsValidResult(model);

            if (_isvalid != string.Empty)
            {
                SetErrorMessage(_isvalid);
                return(View(nameof(EditResult), model));
            }

            var currentId = model.Id;

            if (service.CaseSessionResult_SaveData(model))
            {
                SetAuditContext(service, SourceTypeSelectVM.CaseSessionResult, model.Id, currentId == 0);
                this.SaveLogOperation(currentId == 0, model.Id);
                SetSuccessMessage(MessageConstant.Values.SaveOK);

                if ((model.SessionResultId == NomenclatureConstants.CaseSessionResult.S_opredelenie_za_otvod) ||
                    (model.SessionResultId == NomenclatureConstants.CaseSessionResult.S_razporejdane_za_otvod))
                {
                    if (currentId == 0)
                    {
                        if (model.CaseLawUnitByCase != null)
                        {
                            var check = model.CaseLawUnitByCase.Where(x => x.Checked).FirstOrDefault();
                            if (check != null)
                            {
                                return(RedirectToAction("AddEditDismisal", "CaseLawUnit", new { lawUnitId = int.Parse(check.Value) }));
                            }
                        }
                    }
                }

                if (model.CallFromActId > 0)
                {
                    return(RedirectToAction("Edit", "CaseSessionAct", new { id = model.CallFromActId }));
                }
                else
                {
                    return(RedirectToAction(nameof(Preview), new { id = model.CaseSessionId }));
                }
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }

            return(View(nameof(EditResult), model));
        }
        /// <summary>
        /// Добавяне на резултат
        /// </summary>
        /// <param name="caseSessionId"></param>
        /// <returns></returns>
        public IActionResult AddResult(int caseSessionId, int CallFromActId)
        {
            if (!CheckAccess(service, SourceTypeSelectVM.CaseSessionResult, null, AuditConstants.Operations.Append, caseSessionId))
            {
                return(Redirect_Denied());
            }

            var caseSession = service.CaseSessionVMById(caseSessionId);
            var model       = new CaseSessionResultEditVM()
            {
                CaseId            = caseSession.CaseId,
                CourtId           = caseSession.CourtId,
                CaseSessionId     = caseSessionId,
                IsActive          = true,
                IsMain            = !service.IsExistMainResult(caseSessionId),
                CaseLawUnitByCase = lawUnitService.GetCheckListCaseLawUnitByCaseAll(caseSession.CaseId),
                CallFromActId     = CallFromActId
            };

            SetViewbagResult(caseSessionId);
            return(View(nameof(EditResult), model));
        }