CalMonthController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. {
  38. DateTime str1 = DateTime.Parse($"{x.Year}-{x.Month}-01");
  39. DateTime str2 = DateTime.Parse($"{y.Year}-{y.Month}-01");
  40. return str2.CompareTo(str1);
  41. });
  42. return lstAll;
  43. }
  44. }
  45. }