C
C#2y ago
bookuha

❔ Get id from query or DTO

Imagine I have the next two entities class Task{ public int Id {get;set;} public string Desc {get;set;} public int AssignmentId {get;set;} public Assignment Assignment {get;set;} class Assignment{ public int Id {get; set;} public ICollection<Task> Tasks {get;set;} } What would be the best way to POST a task to an existing assignment? How would endpoint and incoming DTO look like? 1) /assignments/3/tasks Receive TaskDTO1{ string Desc } and assignment id to your controller method, call service method that will retrieve assignment by the id and append a task to its task collection, then save 2) /tasks/ Receive TaskDTO2{ string Desc, int AssignmentId } in your controller method, call service method that will create a task entity, retrieve a corresponding assignment by id (AssignmentId from dto2) and fill the Task.Assignment with this assignment, then save Which way looks better to you? Why?
3 Replies
Shirasho
Shirasho2y ago
Assignments can have more than one task, but not the other way around. The former expresses this relationship. There is the assumption you always have the assignment Id on hand.
qqdev
qqdev2y ago
1). Because it is resource-based which is what you usually want
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
✅ Is it possible to check how long it would take for the battery to finish charging?Hi, I know i got a lot of information form my previous thread, but I would still like to access more❔ ✅ How do I import System.Windows.Devices.Power?I know I need to make a namespace, but how? It doesn't show up on the list and I just want to aggrav❔ Capture parameter value with Moq decorated with the 'in' keywordHello! I'm writing Unit Tests for a library with a lot of structs, which utilizes the `in` keyword t✅ Mention user in footer in Embed (.Net 6)Hi, I'm trying to mention the user to used the command in the footer but I can only make it write itMap complex object (dictionary) from appsettings.json to modelHi, i have a complex appsettings.json like this ``` "interceptor": { "interactionType": "redire❔ Passing a list of values to Stored Procedure in EF CoreHey devs, I would like to know whether it is possible to pass a list of values as a parameter to a ✅ Input into list (Console app)**Program** I want the user to keep creating accounts, and then put them inside at list **Example o❔ POST request in swagger shows entire schema and parts of it are not needed in request bodyI have a one to one relationship between Product and CartItem, in the POST request for Product the C❔ ❔ Docker-Compose cannot find DockerfileHey! when i try to do docker-compose build i get this error : `failed to solve: rpc error: code = U❔ IStringLocalizer with a GenericClass T in Resource filenameI'm using `Microsoft.Extensions.Localization.IStringLocalizer` to localize my strings via Resources