using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; 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 DeviceController : ControllerBase { private readonly IConfiguration _cfg; private readonly IRepository _productRepo; private readonly IRepository _categoryRepo; public DeviceController(IConfiguration cfg, IRepository productRepo, IRepository categoryRepo) { this._cfg = cfg; this._productRepo = productRepo; this._categoryRepo = categoryRepo; } [HttpPost] public ActionResult GetProducts() { 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() }); return Ok(model); } catch (Exception ex) { ex.PrintStack(); return Problem(ex.Message); } } } }