using System.ComponentModel;
using Admin.Bodk.Customer.Modules;
using Admin.NET.Core;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace Admin.Bodk.Customer;
///
/// 设备管理服务
///
[ApiDescriptionSettings(Order = 2)]
public class CustomerService: IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _customer;
public CustomerService(SqlSugarRepository customer)
{
_customer = customer;
}
///
/// 获取客户列表
///
///
///
[DisplayName("获取客户列表")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public async Task> PostCustomerList(CustomerInput input)
{
return await _customer.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.Name),
m => m.Name != null && m.Name.Contains(input.Name))
.ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 增加客户
///
///
///
[UnitOfWork]
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
[DisplayName("增加客户")]
public async Task AddCustomer(CustomerDot input)
{
if(input is null) throw Oops.Oh("参数不能为空");
var customer = input.Adapt();
var newEquipment = await _customer.AsInsertable(customer).ExecuteReturnEntityAsync();
return newEquipment.Id;
}
}