public override IResult <MessageModel> Execute ( string message, IUserContext userContext ) { if (!userContext.IsAuthenticated) { return(ResultFactory .Unauthorized("You must authenticate prior to creating messages.")); } if (string.IsNullOrWhiteSpace(message)) { return(ResultFactory .Failure("The specified message is empty.")); } var createdMessage = new MessageModel(Guid.NewGuid(), userContext.Username, message.Trim(), _clock.GetCurrentInstant()); _state.Add(createdMessage); _logger.LogInformation($"Message ({createdMessage.Id}) created by: {createdMessage.Username}."); return(ResultFactory .Success(createdMessage)); }
public IActionResult OnPost() { if (ModelState.IsValid) { messages.Add(message); } return(RedirectToPage("./MessageBoard")); }