CalMonthController.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity;
  9. namespace wispro.sp.api.Controllers
  10. {
  11. [Route("api/[controller]/[action]")]
  12. [ApiController]
  13. [Authorize]
  14. public class CalMonthController : ControllerBase
  15. {
  16. spDbContext Context;
  17. public CalMonthController(spDbContext context)
  18. {
  19. Context = context;
  20. }
  21. public CalMonth GetHandlingMonth()
  22. {
  23. CalMonth calMonth= Context.CalMonths.Where<CalMonth>(c => c.Status != 4).FirstOrDefault();
  24. if(calMonth== null)
  25. {
  26. return null;
  27. }
  28. else
  29. {
  30. return calMonth;
  31. }
  32. }
  33. public List<CalMonth> GetAll()
  34. {
  35. var lstAll= Context.CalMonths.ToList();
  36. lstAll.Sort((x,y)=> {
  37. DateTime str1 = DateTime.Parse( $"{x.Year}-{x.Month}-01");
  38. DateTime str2 = DateTime.Parse($"{y.Year}-{y.Month}-01");
  39. return str2.CompareTo(str1);
  40. });
  41. return lstAll;
  42. }
  43. }
  44. }