public void SaveCar(Cars carToSave, int recordId, string userId) { var user = _db.Users.Find(userId); if (carToSave.Id == 0) { carToSave.Record = _db.Record.Find(recordId); carToSave.UserId = user.Id; _db.Cars.Add(carToSave); _db.SaveChanges(); } else { var original = _db.Cars.Find(carToSave.Id); original.Record = _db.Record.Find(recordId); original.CarType = carToSave.CarType; original.EmptyOrLoaded = carToSave.EmptyOrLoaded; original.RailcarNumber = carToSave.RailcarNumber; original.ShippedBy = carToSave.ShippedBy; } }
/// <summary> /// Add new movie to db. /// </summary> public void CreateCar(Cars carToCreate) { _db.Cars.Add(carToCreate); _db.SaveChanges(); }