'Differnet data models using the same properties in PUT, POST and GET
I have GetAccount (GET), UpdateAccount (PUT) and CreateAccount (POST) REST API methods.
All of these methods are related to the ACCOUNTS table in a database.
I have created 3 models Account, UpdateAccount and CreateAccount.
Account
public int AccountID {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
public string Email {get; set;}
public bool DeletedYN {get; set;}
UpdateAccount
public string FirstName {get; set;}
public string LastName {get; set;}
public string Email {get; set;}
public bool DeletedYN {get; set;}
CreateAccount
public string FirstName {get; set;}
public string LastName {get; set;}
public string Email {get; set;}
GetAccount returns an Account. UpdateAccount requires an UpdateAccount as a parameter and returns an Account. CreateAccount requies a CreateAccount as a parameter and returns an AccountID.
See how there are a lot of properties that are the same across each model. But obviously I do not want a user to update an AccountID or create a deleted Account. Its a lot repeated code and there can be much bigger models that are set out in this way.
What is the best way not repeat the same properties through these models? For some reason an AccountBase class doesn't feel right..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
