public virtual void Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { if (vehicleForm == null) { throw new ArgumentNullException("vehicleForm"); } try { var vehicle = vehicleForm.ConvertToEntity(userId); _vehicleRepository.Create(userId, vehicle); if (photoFile == null) { return; } // the double reference between vehicle and photo is a potential source of pain var photo = photoFile.ConvertToEntity(); _photoRepository.Create(vehicle.VehicleId, photo); vehicle.PhotoId = photo.VehiclePhotoId; _vehicleRepository.Update(vehicle); } catch (InvalidOperationException ex) { throw new BusinessServicesException(Resources.UnableToCreateVehicleExceptionMessage, ex); } }
public virtual int Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { if (vehicleForm == null) throw new ArgumentNullException("vehicleForm"); var vehicle = vehicleForm.ConvertToEntity(userId); _vehicleRepository.Create(userId, vehicle); if (photoFile != null) { // the double reference between vehicle and photo is a potential source of pain var photo = photoFile.ConvertToEntity(); _photoRepository.Create(vehicle.VehicleId, photo); vehicle.PhotoId = photo.VehiclePhotoId; _vehicleRepository.Update(vehicle); } return vehicle.Id; }
public virtual void Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { if (vehicleForm == null) throw new ArgumentNullException("vehicleForm"); try { var vehicle = vehicleForm.ConvertToEntity(userId); _vehicleRepository.Create(userId, vehicle); if (photoFile == null) return; // the double reference between vehicle and photo is a potential source of pain var photo = photoFile.ConvertToEntity(); _photoRepository.Create(vehicle.VehicleId, photo); vehicle.PhotoId = photo.VehiclePhotoId; _vehicleRepository.Update(vehicle); } catch (InvalidOperationException ex) { throw new BusinessServicesException(Resources.UnableToCreateVehicleExceptionMessage, ex); } }
public virtual int Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { if (vehicleForm == null) { throw new ArgumentNullException("vehicleForm"); } var vehicle = vehicleForm.ConvertToEntity(userId); _vehicleRepository.Create(userId, vehicle); if (photoFile != null) { // the double reference between vehicle and photo is a potential source of pain var photo = photoFile.ConvertToEntity(); _photoRepository.Create(vehicle.VehicleId, photo); vehicle.PhotoId = photo.VehiclePhotoId; _vehicleRepository.Update(vehicle); } return(vehicle.Id); }
public virtual void Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { try { var existing = _vehicleRepository.GetVehicle(userId, vehicleForm.VehicleId); int? photoId = null; if (existing != null) { if (photoFile != null) { if (existing.PhotoId > 0) { _photoRepository.Delete(existing.PhotoId); } var dataPhoto = photoFile.ConvertToEntity(); // should we put this in its own try block? _photoRepository.Create(vehicleForm.VehicleId, dataPhoto); photoId = dataPhoto.VehiclePhotoId = dataPhoto.VehiclePhotoId; } var vehicle = vehicleForm.ConvertToEntity(userId, includeVehicleId: true); vehicle.PhotoId = (photoId != null) ? photoId.Value : existing.PhotoId; _vehicleRepository.Update(vehicle); } else { throw new BusinessServicesException(Resources.UnableToUpdateVehicleExceptionMessage); } } catch (InvalidOperationException ex) { throw new BusinessServicesException(Resources.CannotFindVehicleToUpdateExceptionMessage, ex); } }