Exemplo n.º 1
0
        /// <summary>
        /// 更新API
        /// </summary>
        /// <param name="api"></param>
        public bool Update(API api)
        {
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();

            DBAPIDoc dbApiDoc = ConvertModelHelper.ToDBAPIModel(api);

            if (dbApiDoc == null) return false;

            var apid = (from q in context.APIDocs
                           where q.APIDocId == api.Id.Value
                           select q).FirstOrDefault();

            if(apid == null)
            {
                context.APIDocs.Add(dbApiDoc);
            }
            else
            {
                apid.Parameters = dbApiDoc.Parameters;
                apid.Title = dbApiDoc.Title;
                apid.Description = dbApiDoc.Description;
                apid.CategoryId = dbApiDoc.CategoryId;
                apid.RequestUrl = dbApiDoc.RequestUrl;
                apid.RequestType = dbApiDoc.RequestType;
                apid.NeedAuth = dbApiDoc.NeedAuth;
                apid.ActionTypes = dbApiDoc.ActionTypes;
                apid.ResponseDemoes = dbApiDoc.ResponseDemoes;
                apid.Errors = dbApiDoc.Errors;
            }
            context.SaveChanges();

            return true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建API
        /// </summary>
        /// <param name="api"></param>
        public bool Insert(API api)
        {
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();

            DBAPIDoc dbApiDoc = ConvertModelHelper.ToDBAPIModel(api);

            if(dbApiDoc ==null) return false;

            var apid = (from q in context.APIDocs
                           where q.APIDocId == api.Id.Value
                           select q).FirstOrDefault();

            if (apid == null)
            {
                context.APIDocs.Add(dbApiDoc);

                context.SaveChanges();

                return true;
            }
            else
                return false;
        }
Exemplo n.º 3
0
        public static DBAPIDoc ToDBAPIModel(API api)
        {
            if (api == null) return null;

            IList<DBParameter> dbParameters = new List<DBParameter>();

            foreach (Parameter pa in api.Request.ParameterSet)
            {
                dbParameters.Add(ToDBParameterModel(api.Id.Value, pa, ParameterType.Request));
            }

            foreach (Parameter pa in api.Response.ParameterSet)
            {
                dbParameters.Add(ToDBParameterModel(api.Id.Value, pa, ParameterType.Response));
            }

            IList<DBResponseDemo> responseDemos = new List<DBResponseDemo>();
            foreach (ResponseDemo demo in api.Response.DemoSet)
            {
                responseDemos.Add(ToDBResponseDemoModel(api.Id.Value, demo));
            }

            IList<DBError> errors = new List<DBError>();
            foreach (ErrorCode code in api.Response.ErrorCodeSet)
            {
                errors.Add(ToDBErrorModel(api.Id.Value,code));
            }

            return new DBAPIDoc
            {
                Parameters = dbParameters,
                APIDocId = api.Id.Value,
                Title = api.Title,
                Description = api.Description,
                CategoryId = api.CategoryId.Value,
                RequestUrl = api.Request.Url,
                RequestType = (byte)api.Request.RequestType,
                NeedAuth = api.Request.NeedAuth,
                ActionTypes = api.Request.ActionType,
                ResponseDemoes = responseDemos,
                Errors = errors
            };
        }