using HaBookCms.AzureCosmos.CosmosDB.Interfaces; using HaBookCms.Core.Models.Syllabus; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace HaBookCms.Contest.Controllers { [Route("api/syllabus")] [ApiController] public class SyllabusController : BaseController { public IAzureCosmosDBRepository _aAzureCosmosDBRepository; public SyllabusController(IAzureCosmosDBRepository aAzureCosmosDBRepository) { _aAzureCosmosDBRepository = aAzureCosmosDBRepository; } [HttpPost] [Route("save")] [EnableCors("any")] [AllowAnonymous] public async Task Save(Syllabus root) { return await _aAzureCosmosDBRepository.Save(root); } [HttpGet] [Route("getById")] [EnableCors("any")] [AllowAnonymous] public object GetById(string id ) { var ss = _aAzureCosmosDBRepository.FindAll().Result.Where(s => s.id == id).ToList().SingleOrDefault(); if (ss != null) { return ss; } else { return ""; } } [HttpGet] [Route("getAll")] [EnableCors("any")] [AllowAnonymous] public object GetAll() { Listsyllabi= _aAzureCosmosDBRepository.FindAll().Result; if (syllabi != null) { return syllabi; } else { return ""; } } } }