Esempio n. 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            var isAuthorized = await Authenticator.AuthenticateRequestForScopeAndRole(req, "CMS.Articles.Read", "Articles.Read", log);

            if (!isAuthorized)
            {
                return(new UnauthorizedResult());
            }

            log.LogInformation("Getting all articles.");

            IEnumerable <Article> articleCollection;

            try
            {
                articleCollection = await CmsDb.GetArticlesAsync("SELECT * FROM c");
            }
            catch (Exception ex)
            {
                log.LogError($"Error loading articles: {ex.Message}");
                return(new InternalServerErrorResult());
            }

            log.LogInformation("Successfully retrieved all articles.");

            return(new OkObjectResult(articleCollection));
        }
Esempio n. 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Getting all published articles.");

            IEnumerable <Article> articleCollection;

            try
            {
                articleCollection = await CmsDb.GetArticlesAsync("SELECT * FROM Articles a WHERE a.isPublished = true ORDER BY a.publicationDate DESC");
            }
            catch (Exception ex)
            {
                log.LogError($"Error loading articles: {ex.Message}");
                return(new InternalServerErrorResult());
            }

            log.LogInformation("Successfully retrieved all articles.");

            return(new OkObjectResult(articleCollection));
        }