Пример #1
0
 public static Qna.Backend.WireModels.SessionResults ToWireModel(this SessionResults sessionResults)
 {
     return(new Qna.Backend.WireModels.SessionResults()
     {
         Id = sessionResults.Id,
         SessionId = sessionResults.SessionId,
         SessionName = sessionResults.SessionName,
         Questions = sessionResults.Questions.Select(q => q.ToWireModel()).ToList()
     });
 }
Пример #2
0
        public static async Task <IActionResult> RunGetSessionResults(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "sessions/{sessionId}/results")] HttpRequest req,
            string sessionId,
            [CosmosDB(
                 databaseName: "%cosmosdbname%",
                 collectionName: "%cosmoscollectionname%",
                 ConnectionStringSetting = "cosmosconnectionstring",
                 PartitionKey = "session-{sessionId}",
                 Id = "sessionresults-{sessionId}")] CosmosModels.SessionResults sessionResults,
            ILogger log)
        {
            log.LogInformation("GetSessionResults was called.");

            if (String.IsNullOrWhiteSpace(sessionId))
            {
                log.LogError("Invalid session id provided");
                return(new BadRequestObjectResult("Please provide a valid session id"));
            }
            else
            {
                if (sessionResults == null)
                {
                    log.LogError("Session results not found for session: " + sessionId);
                    return(new NotFoundObjectResult("Session not found: " + sessionId));
                }
                else
                {
                    log.LogInformation("Returned session with id: " + sessionId);

                    // return ok
                    return(new OkObjectResult(
                               sessionResults.ToWireModel()
                               ));
                }
            }
        }