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.ComponentModel.DataAnnotations; 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 _deviceRepo; public DeviceController(IConfiguration cfg, IRepository deviceRepo) { this._cfg = cfg; this._deviceRepo = deviceRepo; } [HttpPost] public ActionResult GetDevice([Required]string number) { try { 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) { ex.PrintStack(); return Problem(ex.Message); } } } }