Пример #1
0
        /// <summary>
        /// 创建Domain
        /// </summary>
        /// <param name="domain"></param>
        public bool Insert(Domain domain)
        {
            DBDomain dbModel = ConvertModelHelper.ToDBDomainModel(domain);

            APIDoc_WebDBContext context = new APIDoc_WebDBContext();
            var dbDomain = (from q in context.Domains
                            where q.DomainId == domain.Id.Value
                          select q).FirstOrDefault();

            if (dbDomain == null)
            {
                context.Domains.Add(dbModel);
                context.SaveChanges();
                return true;
            }
            else
                return false;
        }
Пример #2
0
        /// <summary>
        /// 更新Domain
        /// </summary>
        /// <param name="domain"></param>
        public bool Update(Domain domain)
        {
            DBDomain dbModel = ConvertModelHelper.ToDBDomainModel(domain);
            if (dbModel == null) return false;
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();
            var dbDomain = (from q in context.Domains
                            where q.DomainId == domain.Id.Value
                            select q).FirstOrDefault();

            if (dbDomain == null)
            {
                context.Domains.Add(dbModel);

            }
            else
            {
                dbDomain.Title = dbModel.Title;
                dbDomain.Description = dbModel.Description;
                dbDomain.RootUrl = dbModel.RootUrl;
            }
            context.SaveChanges();
            return true;
        }
Пример #3
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;
        }
Пример #4
0
        /// <summary>
        /// 创建Category
        /// </summary>
        /// <param name="category"></param>
        public bool Insert(Category category)
        {
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();

            DBCategory dbModel = ConvertModelHelper.ToDBCategoryModel(category);

            if (dbModel == null) return false;

            var dbCategory = (from q in context.Categories
                            where q.CategoryId == category.Id.Value
                            select q).FirstOrDefault();

            if (dbCategory == null)
            {
                context.Categories.Add(dbCategory);

                context.SaveChanges();

                return true;
            }
            else
                return false;
        }
Пример #5
0
        /// <summary>
        /// 更新Category
        /// </summary>
        /// <param name="category"></param>
        public bool Update(Category category)
        {
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();

            DBCategory dbModel = ConvertModelHelper.ToDBCategoryModel(category);

            if (dbModel == null) return false;

            var dbCategory = (from q in context.Categories
                              where q.CategoryId == category.Id.Value
                              select q).FirstOrDefault();

            if (dbCategory == null)
            {
                context.Categories.Add(dbModel);
            }
            else
            {
                dbCategory.DomainId = dbModel.DomainId;
                dbCategory.Title = dbModel.Title;
                dbCategory.ParentId = dbModel.ParentId;
            }
            context.SaveChanges();
            return true;
        }
Пример #6
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;
        }