public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); try { string userName = req.Query["userName"]; string companyId = req.Query["companyId"]; string learningPath = req.Query["learningPath"]; BlobApi blobApi = await BlobApi.Instance; ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath); CloudSkillApi cloudSkillApi = await CloudSkillApi.Instance; int progress = await cloudSkillApi.GetUserProgressAsync(savedContest.ContestId, userName); return(new OkObjectResult(progress)); } catch (Exception ex) { log.LogWarning($"GetLearnerProgress failed ({ex.Message})"); return(new BadRequestObjectResult(ex.Message)); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); try { string companyId = req.Query["companyId"]; if (string.IsNullOrWhiteSpace(companyId)) { throw new ArgumentNullException($"{nameof(companyId)} is blank."); } string learningPath = req.Query["learningPath"]; if (string.IsNullOrWhiteSpace(learningPath)) { throw new ArgumentNullException($"{nameof(learningPath)} is blank."); } BlobApi blobApi = await BlobApi.Instance; ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath); string sponsorEmail = savedContest.MicrosoftAccountSponsor; return(new OkObjectResult(sponsorEmail)); } catch (Exception ex) { log.LogWarning($"Unable to get sponsor email. {ex}"); return(new BadRequestObjectResult($"{ex}")); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger GetLearnerProgress function processed a request."); try { string userName = req.Query["userName"]; if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentNullException($"{nameof(userName)} is blank."); } string contestId = req.Query["contestId"]; if (string.IsNullOrWhiteSpace(contestId)) { string companyId = req.Query["companyId"]; if (string.IsNullOrWhiteSpace(companyId)) { throw new ArgumentNullException($"{nameof(companyId)} is blank."); } string learningPath = req.Query["learningPath"]; if (string.IsNullOrWhiteSpace(learningPath)) { throw new ArgumentNullException($"{nameof(learningPath)} is blank."); } BlobApi blobApi = await BlobApi.Instance; ContestResponse savedContest = await blobApi.GetContest(companyId, learningPath); contestId = savedContest.ContestId; } CloudSkillApi cloudSkillApi = await CloudSkillApi.Instance; Learner learner = await cloudSkillApi.GetLearner(contestId, userName); if (learner == null) { return(new OkObjectResult(-1)); } if (learner.PercentComplete == null) { throw new NullReferenceException($"Unable to determine percent complete."); } return(new OkObjectResult(learner.PercentComplete)); } catch (Exception ex) { log.LogWarning($"GetLearnerProgress failed ({ex.Message})"); return(new BadRequestObjectResult(ex.Message)); } }
public static async Task <IActionResult> RunHttp( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); LearnerRequest request = JsonConvert.DeserializeObject <LearnerRequest>(requestBody); BlobApi blobApi = await BlobApi.Instance; ContestResponse contest = await blobApi.GetContest(request.CustomerId, request.CollectionName); CloudSkillApi cloudSkillApi = await CloudSkillApi.Instance; Learner learnerReponse = await cloudSkillApi.AddLearnerAsync(contest.ContestId, request.LearnerId); return(new OkObjectResult(contest.CollectionUrl)); } catch (Exception ex) { log.LogError(string.Format("Error in AddLearnerToChallengeFromHttp: {0}", ex.Message)); return(new BadRequestObjectResult(ex.Message)); } }