public function editInventory()
 {
     if (strlen($_REQUEST['new_make']) > 0 && strlen($_REQUEST['new_model']) > 0) {
         $make = new Make();
         $make->setTitle($_REQUEST['new_make'])->create();
         $model = new Model();
         $model->setTitle($_REQUEST['new_model'])->setMake($make)->create();
     } else {
         $model = new Model($_REQUEST['model_id']);
         $model->loadMake();
     }
     $auto = new Auto($_REQUEST['id']);
     $auto->setPrice($_REQUEST['price'])->setPricePostfix($_REQUEST['price_postfix'])->setTypeId($_REQUEST['type_id'])->setInventoryNumber($_REQUEST['inventory_number'])->setVin($_REQUEST['vin'])->setMakeId($model->getMakeId())->setModelId($model->getId())->setYear($_REQUEST['year'])->setDescription($_REQUEST['description'])->setIsVisible($_REQUEST['is_visible'])->setIsFeatured($_REQUEST['is_featured'])->setInterior($_REQUEST['interior'])->setExterior($_REQUEST['exterior'])->setOdometerReading($_REQUEST['odometer_reading']);
     /* Features */
     $auto->setFeatures(NULL);
     $features = json_decode(stripslashes($_REQUEST['features']), TRUE);
     foreach ($features as $f) {
         if ($f['remove'] == 0) {
             $feature = new AutoFeature();
             $feature->setId(uniqid())->setFeatureId($f['feature_id'])->setFeatureTitle($f['title'])->setValue($f['value'])->setCreatedAt(time())->setUpdatedAt(time());
             $auto->addFeature($feature);
         }
     }
     $auto->update();
     $images = json_decode(stripslashes($_REQUEST['images']), TRUE);
     /** Remove deleted images */
     if ($auto->getImageCount() > 0) {
         foreach ($auto->getImages() as $image) {
             $delete_me = TRUE;
             foreach ($images as $i) {
                 if ($image->getId() == $i['id']) {
                     $delete_me = FALSE;
                     break;
                 }
             }
             if ($delete_me) {
                 $auto->deleteImage($image->getId());
             }
         }
     }
     foreach ($images as $i) {
         /** Add new images */
         if ($i['id'] == 0) {
             $image = new Image();
             $image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->create();
             $auto->addImage($image);
         } else {
             $image = new Image($i['id']);
             $image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->update();
             $auto->setImage($i['id'], $image);
         }
     }
     return $auto->getId();
 }