SyllabusController.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using HaBookCms.AzureCosmos.CosmosDB.Interfaces;
  2. using HaBookCms.Core.Models.Syllabus;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Cors;
  5. using Microsoft.AspNetCore.Mvc;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace HaBookCms.Contest.Controllers
  11. {
  12. [Route("api/syllabus")]
  13. [ApiController]
  14. public class SyllabusController : BaseController
  15. {
  16. public IAzureCosmosDBRepository _aAzureCosmosDBRepository;
  17. public SyllabusController(IAzureCosmosDBRepository aAzureCosmosDBRepository) {
  18. _aAzureCosmosDBRepository = aAzureCosmosDBRepository;
  19. }
  20. [HttpPost]
  21. [Route("save")]
  22. [EnableCors("any")]
  23. [AllowAnonymous]
  24. public async Task<object> Save(Syllabus root) {
  25. return await _aAzureCosmosDBRepository.Save<Syllabus>(root);
  26. }
  27. [HttpGet]
  28. [Route("getById")]
  29. [EnableCors("any")]
  30. [AllowAnonymous]
  31. public object GetById(string id )
  32. {
  33. var ss = _aAzureCosmosDBRepository.FindAll<Syllabus>().Result.Where(s => s.id == id).ToList().SingleOrDefault();
  34. if (ss != null) {
  35. return ss;
  36. }
  37. else { return ""; }
  38. }
  39. [HttpGet]
  40. [Route("getAll")]
  41. [EnableCors("any")]
  42. [AllowAnonymous]
  43. public object GetAll()
  44. {
  45. List<Syllabus>syllabi= _aAzureCosmosDBRepository.FindAll<Syllabus>().Result;
  46. if (syllabi != null)
  47. {
  48. return syllabi;
  49. }
  50. else { return ""; }
  51. }
  52. }
  53. }