public IActionResult OnPost(string submit, string Comment) { switch (submit) { case "cmnt": messages.Update(message); messages.Commit(); break; case "lyk": message.Like += 1; messages.Update(message); messages.Commit(); break; } return(RedirectToPage("./MessageBoard")); }
public override IResult <MessageModel> Execute ( MessageUpdate request, IUserContext userContext ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!userContext.IsAuthenticated) { return(ResultFactory .Unauthorized("You must authenticate prior to updating messages.")); } if (string.IsNullOrWhiteSpace(request?.Message)) { return(ResultFactory .Failure("The specified message is empty.")); } var message = _state.Messages .SingleOrDefault(x => x.Id == request.MessageId); if (message == null) { return(ResultFactory .NotFound("The specified message could not be found or does not exist.")); } if (message.Username != userContext.Username) { return(ResultFactory .Forbidden("Modifying messages made by others is disallowed.")); } message = new MessageModel(message.Id, message.Username, request.Message, message.Created, _clock.GetCurrentInstant()); _state.Update(message); _logger.LogInformation($"Message ({message.Id}) updated by: {message.Username}."); return(ResultFactory .Success(message)); }