Exemplo n.º 1
0
        private Result CommonAddCheck(string dataSourceType, DataSource entity)
        {
            return(Result.Success()
                   .ContinueAssert(!string.IsNullOrEmpty(entity.Name), "名称不能为空")
                   .ContinueAssert(!string.IsNullOrEmpty(entity.Code), "编码不能为空")
                   .ContinueAssert(entity.Code.IsAlnum(2, 50), "编码不合法,2-50位且只能包含字母和数字(字母开头)")
                   .ContinueAssert(!string.IsNullOrEmpty(entity.Script), "数据源内容不能为空")
                   .Continue(re =>
            {
                string tempCode = entity.Code;
                entity.ApplicationId = CurrentApplicationId;
                entity.Code = $"{CurrentApplicationCode}.{dataSourceType}.{entity.Code}";

                //检查编码或名称重复
                var checkResult = _dataSourceService.CheckSameCodeOrName(entity);
                if (!checkResult.IsSuccess)
                {
                    return checkResult;
                }
                entity.Code = tempCode;
                return re;
            }));
        }