public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation($"PendingGramercies executed at: {DateTime.UtcNow}"); var result = await _tokenProvider.ValidateToken(req); try { if (result.Status == AccessTokenStatus.Valid && result.Principal.IsInRole(moderatorRoleName)) { GramercyManager gramercyManager = new GramercyManager(); OpResults <Gramercy> gramercyResults = await gramercyManager.GetPendingGramerciesAsync(); if (gramercyResults.Code != Constants.Enums.OperationResultCode.Success) { log.LogInformation($"PendingGramercies error: {gramercyResults.Message}"); return(new BadRequestResult()); } return(new JsonResult(gramercyResults.Results)); } else { return(new UnauthorizedResult()); } } finally { log.LogInformation($"PendingGramercies completed at: {DateTime.UtcNow}"); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation($"GramerciesByUser executed at: {DateTime.UtcNow}"); string recipientId = req.Query["recipientId"]; if (string.IsNullOrEmpty(recipientId)) { return(new JsonResult(new List <Gramercy>())); } try { GramercyManager gramercyManager = new GramercyManager(); OpResults <Gramercy> gramercyResults = await gramercyManager.GetGramerciesByRecipientIdAsync(recipientId); if (gramercyResults.Code != Constants.Enums.OperationResultCode.Success) { log.LogInformation($"GramerciesByUser error: recipient: {recipientId} | {gramercyResults.Message}"); } return(new JsonResult(gramercyResults.Results)); } finally { log.LogInformation($"GramerciesByUser completed at: {DateTime.UtcNow}"); } }
public static async Task Run([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, ILogger log) { log.LogInformation($"TweetSender executed at: {DateTime.UtcNow}"); try { GramercyManager gramercyManager = new GramercyManager(); OperationResult result = await gramercyManager.SendAnonymousGramerciesAsync(); if (result.Code == Constants.Enums.OperationResultCode.Success) { log.LogInformation($"TweetSender result: {result.Code}"); } else { log.LogInformation($"TweetSender result: (Error) {result.Message}"); } } catch (Exception ex) { log.LogInformation($"TweetSender error: {ex.Message}"); } finally { log.LogInformation($"TweetSender completed at: {DateTime.UtcNow}"); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { string twitterId = req.Query["twitterId"]; GramercyManager gramercyManager = new GramercyManager(); OpResult <Gramercy> result = await gramercyManager.GetRandomGramercyAsync(twitterId); return(new OkObjectResult(result.Result)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation($"TweetRecorder executed at: {DateTime.UtcNow}"); IActionResult result = new OkResult(); try { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); Tweet tweet = JsonConvert.DeserializeObject <Tweet>(requestBody); if (string.IsNullOrEmpty(tweet.Message)) { log.LogInformation($"TweetRecorder error: Message not provided."); return(new BadRequestObjectResult("Message is required.")); } if (tweet.Message.Length > 228) { log.LogInformation($"TweetRecorder error: Message provided was {tweet.Message.Length} characters."); return(new BadRequestObjectResult("Message must be less than 229 characters.")); } if (tweet.UserMentions.Length == 0) { log.LogInformation($"TweetRecorder error: No recipients specified."); return(new BadRequestObjectResult("Recipient is required.")); } GramercyManager grammercyManager = new GramercyManager(); OpResult <Gramercy> grammercyResult = await grammercyManager.ProcessTweetAsync(tweet); log.LogInformation($"TweetRecorder result: {grammercyResult.Code}"); } catch (Exception ex) { result = new BadRequestObjectResult(new { message = ex.Message }); log.LogInformation($"TweetRecorder error: {ex.Message}"); } finally { log.LogInformation($"TweetRecorder completed at: {DateTime.UtcNow}"); } return(result); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation($"SaveGramercy executed at: {DateTime.UtcNow}"); var result = await _tokenProvider.ValidateToken(req); try { if (result.Status == AccessTokenStatus.Valid && result.Principal.IsInRole(moderatorRoleName)) { string grammercyId = req.Query["gramercyId"]; string reqStatus = req.Query["status"]; if (string.IsNullOrEmpty(grammercyId) || !int.TryParse(reqStatus, out int status)) { return(new BadRequestResult()); } GramercyManager gramercyManager = new GramercyManager(); OpResult <Gramercy> gramercyResults = await gramercyManager.UpdateGrammercy(grammercyId, status); if (gramercyResults.Code != Constants.Enums.OperationResultCode.Success) { log.LogInformation($"SaveGramercy error: {gramercyResults.Message}"); return(new BadRequestResult()); } return(new JsonResult(gramercyResults.Result)); } else { return(new UnauthorizedResult()); } } finally { log.LogInformation($"SaveGramercy completed at: {DateTime.UtcNow}"); } }