I have 2 controllers (DRIVER Controller and VEHICLE controller) i need to map vehicle with a driver. i have created a partial view where in one can select a vehicle to a particular driver.
Now how to save data from this partial view into Vehicle_driver Table??
Vehicle_driver has these fields
VEHICLE_ID bigint(20) PK
DRIVER_ID varchar(36) PK
SERVICE_START_DATE datetime PK
SERVICE_END_DATE datetime
Vehicle Table has fields like
ID bigint(20) PK
REG_NO varchar(50)
VEHICLE_TYPE int(11)
SERVICE_START_DATE datetime
SERVICE_EXPIRE_开发者_StackOverflow中文版DATE datetime
OWNER_ID varchar(36)
and Driver table has fields called
ID varchar(36) PK
LICENCE_NO varchar(50)
FIRST_NAME varchar(50)
LAST_NAME varchar(50)
ADDRESS varchar(1000)
public Vehicle_driver Assign(Driver d, Vehicle v, DateTime start, DateTime end) {
using (MyContext context = new MyContext()) {
Vehicle_driver assignment = context.CreateObject<Vehicle_driver>();
assignment.VEHICLE_ID = v.ID;
assignment.DRIVER_ID = d.ID;
assignment.SERVICE_START_DATE = start;
assignment.SERVICE_END_DATE = end;
context.Vehicle_drivers.AddObject(assignment);
context.SaveChanges();
return assignment;
}
}
精彩评论