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.
93 lines
2.9 KiB
93 lines
2.9 KiB
using Infrastructure.Application.Services.Settings;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using Platform.Services;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Apis.Controllers
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
[ApiController]
|
|
public class OrganController : ControllerBase
|
|
{
|
|
private readonly ILogger<OrganController> _logger;
|
|
private readonly ISettingService _settingService;
|
|
private readonly IRepository<Organ> _organRepo;
|
|
private readonly IRepository<IoTProduct> _productRepo;
|
|
private readonly IRepository<IoTDevice> _deviceRepo;
|
|
private readonly IHubContext<IoTCenterHub> _hub;
|
|
|
|
public OrganController(
|
|
ILogger<OrganController> logger,
|
|
ISettingService settingService,
|
|
IRepository<Organ> organRepo,
|
|
IRepository<IoTProduct> productRepo,
|
|
IRepository<IoTDevice> deviceRepo,
|
|
IHubContext<IoTCenterHub> hub)
|
|
{
|
|
this._logger = logger;
|
|
this._settingService = settingService;
|
|
this._organRepo = organRepo;
|
|
this._productRepo = productRepo;
|
|
this._deviceRepo = deviceRepo;
|
|
this._hub = hub;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult GetOrgans()
|
|
{
|
|
try
|
|
{
|
|
var model = this._organRepo.Table()
|
|
.OrderBy(o => o.DisplayOrder)
|
|
.ThenBy(o => o.Name)
|
|
.ToList();
|
|
return Ok(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult GetProducts([Required(ErrorMessage = nameof(RequiredAttribute))] string number)
|
|
{
|
|
try
|
|
{
|
|
var organ = this._organRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == number);
|
|
var model = new
|
|
{
|
|
organ.Name,
|
|
organ.Number,
|
|
organ.Image,
|
|
Products = this._productRepo.ReadOnlyTable().Select(o => new
|
|
{
|
|
o.Id,
|
|
o.Name,
|
|
o.Number,
|
|
o.Image,
|
|
o.DisplayOrder,
|
|
Count = _deviceRepo.ReadOnlyTable()
|
|
.Count(d => d.ProductId == o.Id)
|
|
})
|
|
};
|
|
return Ok(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|