Beispiel #1
0
 private bool IsNewRevisionValid()
 {
     if (PoemToEdit.PublishedRevisionId == PUBLISH_NEW_REVISION &&
         NewRevision != null && NewRevision.IsEmpty())
     {
         var fieldName = nameof(PoemToEdit) + "." + nameof(PoemToEdit.PublishedRevisionId);
         ModelState.AddModelError(fieldName, NEW_REVISION_EMPTY_MESSAGE);
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid || !IsNameValid() || !IsNewRevisionValid())
            {
                GetPastRevisionsAndCreateSelectLists(PoemToEdit.Id);
                return(Page());
            }

            if (NewRevision != null && !NewRevision.IsEmpty())
            {
                _writePoemService.SaveNewRevision(PoemToEdit.Id, NewRevision);

                if (PoemToEdit.PublishedRevisionId == PUBLISH_NEW_REVISION)
                {
                    PoemToEdit.PublishedRevisionId = GetLatestRevisionId();
                }
            }

            _writePoemService.UpdatePoem(PoemToEdit);
            ConfirmationMessage = POEM_SAVED_MESSAGE;
            return(RedirectToPage(new { id = PoemToEdit.Id }));
        }