I am working on .Net Core
This is my mission page. Its releated with two table actually.
In the old tradition you have to fill each table before you pick that data from here
but what i want is to add new drivers from here.
To be clear, I can pick two drivers Vin and Jason however if i text here something else and if i press the add mission button It should be added to Drivers table and Missions Table too
I tried:
[HttpPost]
public async Task<ActionResult<List<Mission>>> AddMission(MissionDto request)
{
var driver = _context.Drivers
.include(p=>p.Missions)
.SingleOrDefault(p => p.Name == request.name)
?? new Driver
{
Name = request.Name,
Age = request.Age
//...
//...
};
var newMission = new Mission
{
TimeCreated = Convert.ToDateTime(DateTime.Now.GetDateTimeFormats()[0]),
MissionId = request.ShipmentId,
};
driver.Missions.Add(newMission);
_context.SaveChanges();
}
I have concerns about new drivers to be added. Is it correct to use this way? Thanks in advance for your advice and help.
