Ai
1 Star 0 Fork 10

SyncGithub/OAuthApp

forked from uncle wang/OAuthApp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PropertySettingsController.cs 3.55 KB
一键复制 编辑 原始数据 按行查看 历史
uncle wang 提交于 2022-09-20 14:58 +08:00 . 1,开发文档更新
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OAuthApp.Data;
using Swashbuckle.AspNetCore.Annotations;
using System.ComponentModel.DataAnnotations;
using System;
using OAuthApp.Filters;
using OAuthApp.Services;
using Microsoft.AspNetCore.Authorization;
namespace OAuthApp.Apis
{
[SwaggerTag("应用属性")]
[ServiceFilter(typeof(ApiRequestLoggingAttribute))]
public class PropertySettingsController : BaseController
{
private readonly AppDbContext _context;
public PropertySettingsController(AppDbContext context)
{
_context = context;
}
[HttpGet]
[SwaggerOperation(OperationId = "PropertySettings")]
[EncryptResultFilter]
public IActionResult List([Required]string channelCode,long channelAppId)
{
var result = _context.PropertySettings
.Where(x => x.ChannelCode == channelCode && x.ChannelAppId == channelAppId).ToList();
return OK(result);
}
[HttpPut("{id}")]
[SwaggerOperation(OperationId = "PropertySettingPut")]
public IActionResult Put(long id, PropertySetting appProperty)
{
var item = _context.PropertySettings
.FirstOrDefault(x => x.ID == appProperty.ID);
if (item == null)
{
return Error("不存在的属性");
}
try
{
item.Value = appProperty.Value;
item.Tag = appProperty.Tag;
item.APICanUse = appProperty.APICanUse;
_context.SaveChanges();
}
catch (Exception ex)
{
return Error(ex.Message);
}
return OK(true);
}
[HttpPost]
[SwaggerOperation(OperationId = "PropertySettingPost")]
public IActionResult Post(PropertySetting appProperty)
{
if (_context.PropertySettings.Any(x =>
x.ChannelCode == appProperty.ChannelCode &&
x.ChannelAppId == appProperty.ChannelAppId &&
x.Name == appProperty.Name))
{
return Error("已存在的属性");
}
_context.PropertySettings.Add(appProperty);
_context.SaveChanges();
return OK(new { id = appProperty.ID });
}
[HttpDelete("{id}")]
[SwaggerOperation(OperationId = "PropertySettingDelete")]
public IActionResult Delete(long id)
{
var appProperty = _context.PropertySettings.FirstOrDefault(x => x.ID == id);
if (appProperty == null)
{
return NotFound();
}
_context.PropertySettings.Remove(appProperty);
_context.SaveChanges();
return OK(true);
}
// 免验证获取应用配置信息
[HttpGet("{id}")]
[SwaggerOperation(OperationId = "PropertySetting")]
[AllowAnonymous]
public IActionResult Detail(long id, string tag, string name)
{
var result = _context.PropertySettings
.Where(x => x.ChannelCode.Equals(ChannelCodes.App)
&& x.ChannelAppId == id
&& x.Tag.Equals(tag)
&& x.Name.Equals(name))
.Select(x => new { id = x.ID, settings = x.Value })
.FirstOrDefault();
if (result == null)
{
return Error("不存在的配置");
}
return OK(result);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/sync-github/OAuthApp.git
git@gitee.com:sync-github/OAuthApp.git
sync-github
OAuthApp
OAuthApp
master

搜索帮助