예제 #1
0
    public async Task CannotCreatePageDataWithNullKey()
    {
        var keyName     = Guid.NewGuid().ToString();
        var newPageData = new DtoPageData {
            Key = null, Data = JsonDocument.Parse("{\"key\": \"value1\"}")
        };

        ((await pageDataController.Post(newPageData)).Result as BadRequestObjectResult).StatusCode.Should().Be(400);
    }
예제 #2
0
    public async Task <DtoPageData> AddAsync(DtoPageData pageData)
    {
        var dbPageData = mapper.Map <DbPageData>(pageData);

        await context.PageData.AddAsync(dbPageData);

        await context.SaveChangesAsync();

        return(mapper.Map <DtoPageData>(dbPageData));
    }
예제 #3
0
    public async Task CanGetDifferentPageData() //eventually
    {
        var keyName     = Guid.NewGuid().ToString();
        var newPageData = new DtoPageData {
            Key = keyName, Data = JsonDocument.Parse("{\"key2\": \"value2\"}")
        };
        var createdPageData  = ((await pageDataController.Post(newPageData)).Result as CreatedAtActionResult).Value as DtoPageData;
        var returnedPageData = (await pageDataController.GetByKey(createdPageData.Key)).Value;

        returnedPageData.Key.Should().Be(keyName);
    }
예제 #4
0
    public async Task CanCreatePageData()
    {
        var keyName     = Guid.NewGuid().ToString();
        var newPageData = new DtoPageData {
            Key = keyName, Data = JsonDocument.Parse("{\"key\": \"value1\"}")
        };
        var dtoPageData = ((await pageDataController.Post(newPageData)).Result as CreatedAtActionResult).Value as DtoPageData;

        dtoPageData.Key.Should().Be(keyName);
        dtoPageData.Data.RootElement.GetProperty("key").GetString().Should().Be("value1");
    }
예제 #5
0
    public async Task <ActionResult <DtoPageData> > Post(DtoPageData pageData)
    {
        log.LogDebug("HttpPost Post PageData");
        log.LogInformation("Posting PageData for {PageData}", pageData);
        if (!ModelState.IsValid || string.IsNullOrWhiteSpace(pageData.Key) || pageData.Data == null)
        {
            return(BadRequest(getModelStateErrorMessage()));
        }
        var createdPageData = await pageDataRepository.AddAsync(pageData);

        return(CreatedAtAction(nameof(GetByKey), new { key = createdPageData.Key }, createdPageData));
    }
예제 #6
0
    public async Task EditAsync(string key, DtoPageData pageData)
    {
        var existingDbPageData = await context.PageData.AsNoTracking().FirstOrDefaultAsync(r => r.Key == key);

        var mappedPageData = mapper.Map <DbPageData>(pageData);
        // mappedPageData.ID = existingDbPageData.ID;

        var alteredPageData = mappedPageData with {
            ID = existingDbPageData.ID
        };

        context.Update(alteredPageData);
        await context.SaveChangesAsync();
    }
예제 #7
0
    public async Task <IActionResult> Edit(string key, DtoPageData pageData)
    {
        log.LogInformation("Editing key {key} for page {pageData}", key, pageData);
        if (!ModelState.IsValid)
        {
            return(BadRequest(getModelStateErrorMessage()));
        }
        if (!await pageDataRepository.ExistsAsync(key))
        {
            return(NotFound("Page Data key does not exist"));
        }
        try
        {
            await pageDataRepository.EditAsync(key, pageData);
        }
        catch (DbUpdateConcurrencyException)
        {
            throw;
        }

        return(NoContent());
    }