public async Task <ActionResult> OnPostAsync([FromServices] BlogEntryComponentFactory blogEntryComponentFactory) { if (blogEntryComponentFactory == null) { throw new ArgumentNullException(nameof(blogEntryComponentFactory)); } if (!ModelState.IsValid) { return(Page()); } var component = blogEntryComponentFactory.New(); WorkflowResult result = await component.Create( BlogEntryUpdateRequest.UriKey, BlogEntryUpdateRequest.Title, BlogEntryUpdateRequest.MinutesToRead, BlogEntryUpdateRequest.TextIntro, BlogEntryUpdateRequest.TextEntry, BlogEntryUpdateRequest.KeyWordId ); if (!result.Success) { for (int i = 0; i < result.Errors.Length; i++) { ModelState.AddModelError("", result.Errors[i]); } return(Page()); } return(RedirectToPage("./Edit", new { id = BlogEntryUpdateRequest.UriKey })); }
public async Task <ActionResult> OnPostAsync([FromServices] BlogEntryComponentFactory blogEntryComponentFactory) { if (blogEntryComponentFactory == null) { throw new ArgumentNullException(nameof(blogEntryComponentFactory)); } if (!ModelState.IsValid) { return(Page()); } Option <BlogEntryTextModel> blogEntryOption = await _queryComponent.BlogAsync(Id); if (!blogEntryOption.Any()) { return(RedirectToPage("/NotFound")); } BlogEntryTextModel Blog = blogEntryOption.Single(); Option <BlogEntryComponent> componentResult = await blogEntryComponentFactory.LoadComponentAsynd(Blog.BlogEntryId); if (!componentResult.Any()) { return(RedirectToPage("/NotFound")); } BlogEntryComponent component = componentResult.Single(); WorkflowResult result = await component.Update( BlogEntryUpdateRequest.UriKey, BlogEntryUpdateRequest.Title, BlogEntryUpdateRequest.MinutesToRead, BlogEntryUpdateRequest.TextIntro, BlogEntryUpdateRequest.TextEntry, BlogEntryUpdateRequest.KeyWordId ); if (!result.Success) { for (int i = 0; i < result.Errors.Length; i++) { ModelState.AddModelError("", result.Errors[i]); } } else { Id = BlogEntryUpdateRequest.UriKey; } return(await BindPageModelAndRedirect(true, !result.Success)); }