Example #1
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;
        }
Example #2
0
 public static DBCategory ToDBCategoryModel(Category model)
 {
     if (model == null) return null;
     return new DBCategory
     {
         DomainId = model.DomainId.Value,
         Title = model.Title,
         CategoryId = model.Id.Value,
         ParentId = model.ParentId.Value
     };
 }
Example #3
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;
        }