Edit HTTP POST method to POST different data depending on existing data in .NET Core

Soluble Snake 1 Reputation point
2021-06-24T15:29:15.217+00:00

I'm creating an API for a game that can (for now) only be played over Postman issuing POST and GET requests. It needs to be able to receive POST requests and update the InMemory database based on previous requests. Player state is not an issue - it just needs to allow for a player to issue a request and update a value based on the value of the previous request.

I have a Model that contains the class variables and automatically sets one of the variables to a PlayerScore value (0, initially).

public class Game
{
    public long Id { get; set; }
    public long PlayerScore { get; set; }
    public bool Roll { get; set; }
    public bool IsComplete { get; set; }
    public Game()
    {
        this.PlayerScore = 0;
    }
}

This sets the score to 0 every time the game is played/HTTP POST requests are submitted, but I want to be able to edit this value based on previous turns in the game.

Where should I place this method?

The POST is performed via an 'ActionResult' style method.

Thanks for any help anyone can possibly provide!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,416 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Muthukrishnan Ramasamy 1 Reputation point
    2021-06-24T17:54:15.257+00:00

    Basically you will have to pass the PlayerScore through constructor or using the property setter.

    If you are able to get the player info from source (the database/static variable/file) with the id POSTed you can overwrite the score after it

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.