'Sharing same object across different methods and update accordingly in C# web API
Apologies for my poor English and probably a stupid question. I am a beginner with C# web api.
What I am trying to do is just to do some data manipulation in c# and respond to the frontend (Angular) from the Web APIs.
Here is how my markup
Controller
[HttpGet]
public async Task<ProjectResult> Get(ProjectDetails d)
{
return Ok(_myclass.ProcessData(d));
}
Class Definitions
public class ProjectDetails{
public int pId{get;set;}
public string pName{get;set;}
}
public class ProjectResult{
public datetime startedAt(get;set;)
public int TotalProcessed(get;set;)
public string remark(get;set;)
public int TotalRowsAdded(get;set;)
}
public class myClass{
readonly projectdetails d;
public myClass(){
d = new projectdetails();
}
public async Task<ProjectResult> ProcessData(ProjectDetails d){
d.startedAt=now();
}
private void method1(){
d.TotalProcessed=10;
//some code
}
private void method2(){
d.TotalRowsAdded=100;
//some code
}
private void method3(){
//some code
d.remark="method 3 finished";
}
}
So I think you got my requirement. I need to return the ProjectResult data to frontend SPA. And the project result object needs to be updated at each methods.
So is it the correct way? Please help me to resolve this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
