FloorController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using FMSAdmin.Data;
  5. using FMSAdmin.Models;
  6. using FMSAdmin.Entities;
  7. using FMSApp.Services;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.AspNetCore.Authorization;
  11. using FMSAdmin.Helpers;
  12. using System.Data;
  13. using System.IO;
  14. using OfficeOpenXml;
  15. namespace FMSApp.Controllers {
  16. [Authorize]
  17. [ApiController]
  18. [ApiVersion("1")]
  19. [Route("api/app/[controller]")]
  20. public class FloorController : Controller {
  21. private readonly ILogger<FloorController> _logger;
  22. private readonly FMSContext _context;
  23. private readonly FloorService _service;
  24. public FloorController(
  25. ILogger<FloorController> logger,
  26. FMSContext context,
  27. FloorService service
  28. ) {
  29. _logger = logger;
  30. _context = context;
  31. _service = service;
  32. }
  33. /// <summary>
  34. /// 목록
  35. /// </summary>
  36. [HttpGet]
  37. public IActionResult List([FromQuery]PagingRequest req, [FromQuery] string siteId) {
  38. var query = _FilterAndSort(req);
  39. if (!string.IsNullOrEmpty(siteId)) {
  40. query = query.Where(x => x.SiteId == Util.ToInt(siteId));
  41. }
  42. var list = query.Select(x => new {
  43. x.SiteId,
  44. x.BuildingId,
  45. x.FloorId,
  46. CmSite = new {
  47. x.CmSite.Name,
  48. },
  49. CmBuilding = new {
  50. x.CmBuilding.Name,
  51. },
  52. x.Name,
  53. });
  54. var paging = PagingList.Pagination(list, req.page, req.limit);
  55. return Ok(paging);
  56. }
  57. [HttpGet("[action]")]
  58. public IActionResult Get([FromQuery] string siteId, [FromQuery] string buildingId, [FromQuery] string floorId) {
  59. var floor = _service.GetAll().Where(x => x.SiteId == Util.ToInt(siteId)
  60. && x.BuildingId == Util.ToInt(buildingId)
  61. && x.FloorId == Util.ToInt(floorId)).FirstOrDefault();
  62. return Ok(new {
  63. floor.SiteId,
  64. floor.BuildingId,
  65. BuildingName = floor.CmBuilding?.Name ?? "",
  66. floor.FloorId,
  67. floor.Name,
  68. });
  69. }
  70. // 검색 & 정렬 공통
  71. private IQueryable<CmFloor> _FilterAndSort(PagingRequest req) {
  72. var query = _service.GetAll();
  73. // 기본 Entity 검색
  74. query = query.Filter(req.conditions);
  75. // 기본 Entity 정렬
  76. query = query.Sort(req.sort);
  77. return query;
  78. }
  79. }
  80. }