代码拉取完成,页面将自动刷新
同步操作将从 uncle wang/OAuthApp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。