public async Task <IActionResult> BeginEditAsync([FromQuery] Guid pageId, [FromQuery] bool force) { var page = await pageService.FindPageByIdAsync(pageId); if (page == null) { return(BadRequest()); } var result = new Models.BeginPageEditResult(); var currentEdit = await pageContentService.FindEditByUserAsync(page, HttpContext.RequestAborted); if (currentEdit != null) { if (force) { await pageContentService.DiscardEditAsync(currentEdit, HttpContext.RequestAborted); currentEdit = null; } else { result.CurrentDate = currentEdit.CreatedDate; } } if (currentEdit == null) { currentEdit = await pageContentService.BeginEditAsync(page, HttpContext.RequestAborted); } result.Url = await pageLinkGenerator.GetPathAsync(currentEdit, HttpContext.RequestAborted); return(Ok(result)); }
public async Task DiscardEdit() { var page = await pageService.FindPageByPathAsync("test"); var edit = await pageContentService.BeginEditAsync(page); var newContent = new TestPageContent() { Title = "test2" }; await pageContentService.SetContentAsync(edit, newContent); await pageContentService.DiscardEditAsync(edit); Assert.Null(await pageContentService.FindEditByIdAsync(edit.Id)); var contentData = (TestPageContent)await pageService.GetPageContentAsync(page); Assert.NotNull(contentData); Assert.Equal("test", contentData.Title); }