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.
81 lines
2.4 KiB
81 lines
2.4 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
|
|
namespace UserCenter.Controllers
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ProductController : ControllerBase
|
|
{
|
|
private readonly IConfiguration _cfg;
|
|
private readonly IRepository<Product> _productRepo;
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
public ProductController(IConfiguration cfg,
|
|
IRepository<Product> productRepo,
|
|
IRepository<Device> deviceRepo)
|
|
{
|
|
this._cfg = cfg;
|
|
this._productRepo = productRepo;
|
|
this._deviceRepo = deviceRepo;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult GetProducts()
|
|
{
|
|
try
|
|
{
|
|
var model = this._productRepo.ReadOnlyTable()
|
|
.OrderBy(o => o.DisplayOrder)
|
|
.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);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult GetDevices([Required]string number)
|
|
{
|
|
try
|
|
{
|
|
var model = this._deviceRepo.ReadOnlyTable()
|
|
.Where(o => o.Product.Number == number)
|
|
.OrderBy(o => o.DisplayOrder)
|
|
.Select(o => new
|
|
{
|
|
o.Name,
|
|
o.Number,
|
|
o.DisplayName,
|
|
Image = o.Product.Image,
|
|
o.DisplayOrder,
|
|
o.Data
|
|
});
|
|
return Ok(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |