2020-04-14 16:44:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Falcon.Extend;
|
|
|
|
|
using FAuth.DataBase;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FAuth.DataBase.Tables;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace FAuth.Controllers.api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应用程序控制器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AppController:ApiControllerBase<AppController>
|
|
|
|
|
{
|
|
|
|
|
public AppController(ILogger<AppController> logger,IServiceProvider service) : base(logger,service) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加新应用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="appName">应用名称</param>
|
|
|
|
|
/// <param name="description">应用说明</param>
|
|
|
|
|
/// <returns>应用信息</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(Apps),200)]
|
|
|
|
|
public Apps AddNewApp(string appName,string description) {
|
|
|
|
|
if(appName.IsNullOrEmpty()) {
|
|
|
|
|
throw new ArgumentNullException(nameof(appName));
|
|
|
|
|
}
|
|
|
|
|
var qu = this.Db.Apps.Where(m => m.Name == appName);
|
|
|
|
|
if(qu.Any()) {
|
|
|
|
|
throw new Exception($"应用{appName}已经存在,不可以重复创建!");
|
|
|
|
|
}
|
|
|
|
|
var newApp = new Apps {
|
|
|
|
|
Name = appName,
|
|
|
|
|
Description = description,
|
|
|
|
|
};
|
|
|
|
|
this.Db.Entry(newApp).State = EntityState.Added;
|
|
|
|
|
this.Db.SaveChangesAsync().Wait();
|
|
|
|
|
return newApp;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 11:41:09 +08:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool RemoveApp(string appName) {
|
|
|
|
|
if(appName.IsNullOrEmpty()) {
|
|
|
|
|
throw new ArgumentNullException(nameof(appName));
|
|
|
|
|
}
|
|
|
|
|
var qu = this.Db.Apps.Where(m => m.Name == appName);
|
|
|
|
|
foreach(var item in qu) {
|
|
|
|
|
this.Db.Entry(item).State = EntityState.Deleted;
|
|
|
|
|
}
|
|
|
|
|
this.Db.SaveChangesAsync().Wait();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 16:44:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询app是否注册
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="appName">app名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(Apps),200)]
|
|
|
|
|
public Apps GetApps(string appName) {
|
|
|
|
|
if(string.IsNullOrEmpty(appName))
|
|
|
|
|
throw new ArgumentException("message",nameof(appName));
|
|
|
|
|
var qu = this.Db.Apps.Where(m => m.Name == appName);
|
|
|
|
|
if(qu.Any()) {
|
|
|
|
|
return qu.First();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("没有找到该应用");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|