移动系统liao
2024-05-07 49699dc35dd326b3079fc78d3750f54255069332
CoreCms.Net.Web.Admin/Controllers/System/CodeGeneratorController.cs
@@ -1,7 +1,7 @@
/***********************************************************************
 *            Project: CoreCms
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: hhtp://chuanyin.com
 *                Web: http://chuanyin.com
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
@@ -9,17 +9,22 @@
 ***********************************************************************/
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Chuanyin.Attribute;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities.Distribution;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Repository.UnitOfWork;
using CoreCms.Net.Utility.Helper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
@@ -42,6 +47,8 @@
        private readonly IWebHostEnvironment _webHostEnvironment;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
@@ -51,6 +58,7 @@
            _codeGeneratorServices = codeGeneratorServices;
            _mapper = mapper;
            _webHostEnvironment = webHostEnvironment;
        }
@@ -255,6 +263,39 @@
        #endregion
        #region 生成或者更新数据库
        /// <summary>
        ///  创建和更新数据库
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fileType"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("创建新表")]
        public IActionResult CreateAndUpdateDatabase([FromServices] IUnitOfWork work)
        {
            var jm = new AdminUiCallBack();
            try
            {
                Type[]? types = AssemblyHelper.DbCodeFirstModes("CoreCms.Net.Model",thisAttribute: typeof(SqlCodeFirstAttribute));
                work.GetDbClient().CodeFirst.InitTables(types??new Type[] { });
                jm.code = 0;
                jm.msg = "创建成功";
                return new JsonResult(jm);
            }
            catch (Exception e)
            {
                jm.msg = e.Message + ":-----" + e.StackTrace;
                return new JsonResult(jm);
            }
        }
        #endregion
    }
}