Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to handle different request and response payload

$
0
0

I have few situations where input differs than the output. I use 1 model (DTO) for both input and the output. How should I handle this? Should I separate this to 2 different models for input and output? Or just ignore it somehow in my mapping configuration?

My application is mostly CRUD, but when creating new item I calculate some properties on the server and those properties shouldn't be accepted in input but should be returned in the output. For example, I'm creating a new product, I wanna pass only net price/gross price and tax. But when returning it I want more things to be returned. Also, I don't want to pass Id in my create action in my controller. 

Should I use something like CQRS and create a separate model for each CRUD action?

example expected input:

public class Order
{
    public int ProductId { get; set; }
}

But on the output I want to return entire Product object

so when I POST /orders I pass ProductId, when I GET /orders I receive entire Product.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>