|
|
|
@ -2,8 +2,10 @@
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace UserCenter.Controllers
|
|
|
|
@ -14,33 +16,27 @@ namespace UserCenter.Controllers
|
|
|
|
|
public class DeviceController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _cfg;
|
|
|
|
|
private readonly IRepository<Product> _productRepo;
|
|
|
|
|
private readonly IRepository<Category> _categoryRepo;
|
|
|
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
|
|
|
|
|
|
public DeviceController(IConfiguration cfg,
|
|
|
|
|
IRepository<Product> productRepo,
|
|
|
|
|
IRepository<Category> categoryRepo)
|
|
|
|
|
IRepository<Device> deviceRepo)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._productRepo = productRepo;
|
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
|
this._deviceRepo = deviceRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult GetProducts()
|
|
|
|
|
public ActionResult GetDevice([Required]string number)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var model = this._productRepo.ReadOnlyTable()
|
|
|
|
|
.OrderBy(o => o.DisplayOrder)
|
|
|
|
|
.Select(o => new
|
|
|
|
|
{
|
|
|
|
|
o.Name,
|
|
|
|
|
o.Number,
|
|
|
|
|
o.Image,
|
|
|
|
|
o.DisplayOrder,
|
|
|
|
|
Count = o.Devices.Count()
|
|
|
|
|
});
|
|
|
|
|
var model = this._deviceRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Data)
|
|
|
|
|
.Include(o => o.Product)
|
|
|
|
|
.ThenInclude(o => o.Apis)
|
|
|
|
|
.ThenInclude(o => o.Parameters)
|
|
|
|
|
.Where(o => o.Number == number)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
return Ok(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|