You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace UserCenter.Controllers
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
[ApiController]
|
|
public class NodeController : ControllerBase
|
|
{
|
|
private readonly IConfiguration _cfg;
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
private readonly IRepository<NodeCategory> _nodeCategoryRepo;
|
|
|
|
public NodeController(IConfiguration cfg,
|
|
IRepository<Node> nodeRepo,
|
|
IRepository<NodeCategory> nodeCategoryRepo)
|
|
{
|
|
this._cfg = cfg;
|
|
this._nodeRepo = nodeRepo;
|
|
this._nodeCategoryRepo = nodeCategoryRepo;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult GetNodes()
|
|
{
|
|
try
|
|
{
|
|
//var model = this._nodeCategoryRepo.ReadOnlyTable()
|
|
// .Include(o => o.CategoryNodes)
|
|
// .ThenInclude(o => o.Node)
|
|
// .OrderBy(o => o.DisplayOrder)
|
|
// .Select(o => new
|
|
// {
|
|
// o.Name,
|
|
// o.DisplayOrder,
|
|
// Nodes = o.CategoryNodes.Select(o => o.Node)
|
|
// });
|
|
var model = this._nodeRepo.ReadOnlyTable()
|
|
.Select(o => new
|
|
{
|
|
o.Id,
|
|
o.Name,
|
|
o.Number,
|
|
o.Image,
|
|
o.DisplayOrder,
|
|
Count = o.Devices.Count()
|
|
});
|
|
return Ok(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |