示例#1
0
        public async Task <IActionResult> CreateOrUpdatePlatform(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "platforms")] HttpRequest req,
            [Table(PlatformsTableName)] IAsyncCollector <PlatformEntity> entityCollector)
        {
            if (!ValidatePermission(req))
            {
                return(new UnauthorizedResult());
            }

            string platformDtoJson = await req.ReadAsStringAsync();

            PlatformDto platformDto = JsonConvert.DeserializeObject <PlatformDto>(platformDtoJson);

            PlatformEntity platformEntity = _mapper.Map <PlatformEntity>(platformDto);

            platformEntity.ETag = "*";

            await entityCollector.AddAsync(platformEntity);

            await entityCollector.FlushAsync();

            string      platformGetUrl     = $"{req.Scheme}://{req.Host}/api/platforms/{platformEntity.PartitionKey}";
            PlatformDto updatedPlatformDto = _mapper.Map <PlatformDto>(platformEntity);

            return(new CreatedResult(platformGetUrl, updatedPlatformDto));
        }
示例#2
0
        public IActionResult GetPlatform(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "platforms/{platformId}")] HttpRequest req,
            [LtiAdvantage] LtiToolPublicKey publicKey,
            [Table(PlatformsTableName, "{platformId}", "{platformId}")] PlatformEntity platformEntity)
        {
            if (!ValidatePermission(req))
            {
                return(new UnauthorizedResult());
            }

            PlatformDto platformDto = _mapper.Map <PlatformDto>(platformEntity);

            platformDto.PublicKey = publicKey.PemString;
            platformDto.ToolJwk   = JsonConvert.SerializeObject(publicKey.Jwk);

            return(new OkObjectResult(platformDto));
        }