StudentController.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using CasinosManager.Api.Domain;
  2. using CasinosManager.Api.Dto;
  3. using CasinosManager.Api.Service;
  4. using Microsoft.AspNetCore.Authorization;
  5. using Microsoft.AspNetCore.Mvc;
  6. using System.Linq;
  7. namespace CasinosManager.Api.Controllers
  8. {
  9. [ApiController]
  10. [Authorize]
  11. public class StudentController : ControllerBase
  12. {
  13. // GET api/values
  14. [HttpPost]
  15. [Route("api/student/query")]
  16. public ActionResult<PageListOutput<Student>> Query(StudentQueryInput queryInput)
  17. {
  18. PageListOutput<Student> output = new PageListOutput<Student>();
  19. MockDataService service = new MockDataService();
  20. var query = service.GetStudents();
  21. if (!string.IsNullOrWhiteSpace(queryInput.Name))
  22. {
  23. query = query.Where(o=>o.Name.Contains(queryInput.Name)).ToList();
  24. }
  25. if (queryInput.CreateFrom.HasValue)
  26. {
  27. query = query.Where(o => o.CreateTime>=queryInput.CreateFrom.Value).ToList();
  28. }
  29. if (queryInput.CreateTo.HasValue)
  30. {
  31. query = query.Where(o => o.CreateTime <= queryInput.CreateTo.Value).ToList();
  32. }
  33. int skip = (queryInput.Page - 1) * queryInput.PageSize;
  34. output.Total = query.Count();
  35. output.Data = query.Skip(skip).Take(queryInput.PageSize).ToList();
  36. return output;
  37. }
  38. }
  39. }