How can i update and at the same time how can i insert of two different models
i am developing a project called "CarPaarking application" so need a help. i have written code for displaying parkid's as a link, here if any user clicks on parkid link it will redirect to"/car/create/?parkid" so here user car details will be saved and at same time the pakid status should be active that means user car was parked and when user exit from parking the parkid status should be inactive. how could i write the code.
HERE MY CONTROLLER CODE:
[HttpGet]
public ActionResult Create(string areaname, int pid)
{
var cars = new Tuple<Area, Place>(db.Areas.FirstOrDefault(a => a.ParkingPlaceName == areaname), db.Places.FirstOrDefault(p => p.ParkID == pid));
return View(cars);
}
// POST: Car/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "CarID,AreaID,ParkID,PlaceId,CarNumber,MobileNumber,ParkedTime,Charges,ParkingLeftTime,TotalParkingTime,Status")] Car car, int pid)
{
var pla = db.Places.FirstOrDefault(a => a.ParkID == pid);
var place = (from pl in db.Places
where pl.ParkID == pid
select pl).FirstOrDefault();
place.PlaceId_Status = true;
db.Entry(place).State = EntityState.Modified;
if(ModelState.IsValid)
{
db.Cars.Add(car);
}
db.SaveChanges();
return RedirectToAction("Details");
}