Exemplo n.º 1
0
        public ServiceResult Save(AutoFormInput autoFormInput, AutoBaseModel autoModel)
        {
            //config
            if (autoFormInput.TypeInstance is IAutoConfig)
            {
                Ioc.Resolve <IApIAlaboAutoConfigService>().Save(autoFormInput.TypeFind, autoFormInput.ModelFind);
            }
            else if (autoFormInput.TypeInstance is IAutoForm set)
            {
                var result = set.Save(autoFormInput.ModelFind, autoModel);
                if (!result.Succeeded)
                {
                    return(ServiceResult.Failure(result.ErrorMessages?.FirstOrDefault()));
                }
            }
            else if (autoFormInput.TypeInstance is IEntity)
            {
                var result = Save(autoFormInput.TypeFind, autoFormInput.ModelFind);
                if (!result.Succeeded)
                {
                    return(result);
                }
            }

            return(ServiceResult.Success);
        }
Exemplo n.º 2
0
        public ApiResult Save([FromBody] AutoFormInput autoFormInput)
        {
            if (!this.IsFormValid())
            {
                return(ApiResult.Failure(this.FormInvalidReason()));
            }
            AutoModel.Query = Query;
            Type   typeFind     = null;
            object instanceFind = null;
            var    checkType    = Resolve <IUIBaseService>().CheckType(autoFormInput.Type, ref typeFind, ref instanceFind);

            if (!checkType.Succeeded)
            {
                return(ApiResult.Failure(checkType.ToString()));
            }

            autoFormInput.TypeFind     = typeFind;
            autoFormInput.TypeInstance = instanceFind;
            try {
                autoFormInput.ModelFind = autoFormInput.Model.ToObject(typeFind);
            } catch {
                return(ApiResult.Failure("序列化出错"));
            }

            // 表单数据验证,特性验证
            var model = autoFormInput.ModelFind;

            if (model == null)
            {
                return(ApiResult.Failure("保存数据出错"));
            }

            if (!IsFormValid(ref model, out var error))
            {
                return(ApiResult.Failure(error));
            }

            try
            {
                var result = Resolve <IAutoFormServcie>().Save(autoFormInput, AutoModel);
                return(ToResult(result));
            }
            catch (Exception ex)
            {
                return(ApiResult.Failure(ex.InnerException?.Message));
            }
        }