HolidayWeekendController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 FMSAdmin.Services;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.EntityFrameworkCore;
  12. using FMSAdmin.Helpers;
  13. using System.Data;
  14. using System.IO;
  15. using OfficeOpenXml;
  16. using Newtonsoft.Json;
  17. using Microsoft.AspNetCore.Http;
  18. using System.Collections.Generic;
  19. using System.Collections;
  20. namespace FMSAdmin.Controllers {
  21. [Authorize]
  22. [ApiController]
  23. [ApiVersion("1")]
  24. [Route("api/[controller]")]
  25. public class HolidayWeekendController : Controller {
  26. private readonly ILogger<HolidayWeekendController> _logger;
  27. private readonly FMSContext _context;
  28. private readonly HolidayWeekendService _service;
  29. private readonly StorageHelper _storage;
  30. public HolidayWeekendController(
  31. ILogger<HolidayWeekendController> logger,
  32. FMSContext context,
  33. HolidayWeekendService service,
  34. StorageHelper storage
  35. ) {
  36. _logger = logger;
  37. _context = context;
  38. _service = service;
  39. _storage = storage;
  40. }
  41. /// <summary>
  42. /// 목록
  43. /// </summary>
  44. [HttpGet("{siteId}")]
  45. public IActionResult Get(string siteId) {
  46. var data = _service.Gets(Util.ToInt(siteId));
  47. var sYear = DateTime.Today.Year.ToString();
  48. if (data == null || data.Count() == 0) {
  49. var item = new CmHolidayWeekend {
  50. SiteId = Util.ToInt(siteId),
  51. Site = new CmSite(),
  52. Saturday = false,
  53. Sunday = false,
  54. IsUse = true,
  55. };
  56. return Ok(item);
  57. } else {
  58. var item = data.Select(x => new {
  59. x.SiteId,
  60. Site = new {
  61. x.Site.Name,
  62. },
  63. x.Saturday,
  64. x.Sunday,
  65. x.IsUse,
  66. });
  67. return Ok(item.First());
  68. }
  69. }
  70. /// <summary>
  71. /// 수정
  72. /// </summary>
  73. [HttpPost("{siteId}")]
  74. public IActionResult Save(int siteId, [FromBody] CmHolidayWeekend data) {
  75. if (ModelState.IsValid) {
  76. _service.Save(siteId, data);
  77. } else {
  78. return BadRequest(ModelState);
  79. }
  80. return Ok();
  81. }
  82. }
  83. }