Ai
1 Star 0 Fork 10

SyncGithub/OAuthApp

forked from uncle wang/OAuthApp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TenantPropertiesController.cs 3.15 KB
一键复制 编辑 原始数据 按行查看 历史
uncle wang 提交于 2022-07-29 11:44 +08:00 . 1,新增开始页
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OAuthApp.Tenant;
using Swashbuckle.AspNetCore.Annotations;
using System;
using Microsoft.AspNetCore.Http;
using OAuthApp.Filters;
using OAuthApp.Services;
namespace OAuthApp.Apis
{
[SwaggerTag("租户属性")]
[ServiceFilter(typeof(ApiRequestLoggingAttribute))]
public class TenantPropertiesController : BaseController
{
public TenantPropertiesController(TenantDbContext context,
IHttpContextAccessor contextAccessor)
{
_tenantContext = context;
_tenant = contextAccessor.HttpContext.GetTenantContext();
}
[HttpGet]
[SwaggerOperation(OperationId = "TenantProperties")]
[EncryptResultFilter]
public IActionResult List()
{
var result = _tenantContext.TenantProperties
.Where(x => x.TenantID == _tenant.Id)
.OrderByDescending(x => x.ID)
.ToList();
return OK(result);
}
[HttpGet("{id}")]
[SwaggerOperation(OperationId = "TenantProperty")]
[EncryptResultFilter]
public IActionResult Get(long id)
{
var result = _tenantContext.TenantProperties
.FirstOrDefault(x => x.ID == id);
if (result == null)
{
return NotFound();
}
return OK(result);
}
[HttpPut("{id}")]
[SwaggerOperation(OperationId = "TenantPropertyPut")]
public IActionResult Put(TenantProperty tenantProperty)
{
var item = _tenantContext.TenantProperties
.FirstOrDefault(x => x.ID == tenantProperty.ID);
if (item == null)
{
return Error("不存在的属性");
}
try
{
item.Value = tenantProperty.Value;
_tenantContext.SaveChanges();
}
catch (Exception ex)
{
return Error(ex.Message);
}
return OK(true);
}
[HttpPost]
[SwaggerOperation(OperationId = "TenantPropertyPost")]
public IActionResult Post(TenantProperty tenantProperty)
{
if(_tenantContext.TenantProperties.Any(
x=>x.TenantID==tenantProperty.TenantID&&
x.Name==tenantProperty.Name))
{
return Error("已存在的属性");
}
_tenantContext.TenantProperties.Add(tenantProperty);
_tenantContext.SaveChanges();
return OK(new { id = tenantProperty.ID });
}
[HttpDelete("{id}")]
[SwaggerOperation(OperationId = "TenantPropertyDelete")]
public IActionResult Delete(long id)
{
var result = _tenantContext.TenantProperties
.FirstOrDefault(x => x.ID == id);
if (result == null)
{
return NotFound();
}
_tenantContext.TenantProperties.Remove(result);
_tenantContext.SaveChanges();
return OK(true);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/sync-github/OAuthApp.git
git@gitee.com:sync-github/OAuthApp.git
sync-github
OAuthApp
OAuthApp
master

搜索帮助