public function handle()
 {
     $eventId = $this->request->input('event_id');
     $organizationId = $this->request->input('attendee.organization_id');
     if (empty($eventId)) {
         throw new Exception("EventID empty.");
     }
     if (empty($organizationId)) {
         throw new Exception("OrganizationID empty.");
     }
     $attendeeData = array('event_id' => $eventId, 'organization_id' => $organizationId, 'firstname' => $this->request->input('attendee.firstname'), 'lastname' => $this->request->input('attendee.lastname'), 'email' => $this->request->input('attendee.email'), 'registration_date' => BaseDateTime::now());
     $attendeeApplicationFormData = array('student_phone' => $this->request->input('attendee_application_form.phone'), 'student_grade' => $this->request->input('attendee_application_form.grade'), 'language' => $this->request->input('attendee_application_form.language'), 'sweatshirt_size' => $this->request->input('attendee_application_form.sweatshirt_size'), 'address' => $this->request->input('attendee_application_form.address'), 'city' => $this->request->input('attendee_application_form.city'), 'state' => $this->request->input('attendee_application_form.state'), 'zipcode' => $this->request->input('attendee_application_form.zipcode'), 'country' => 'USA', 'birthdate' => Carbon::parse($this->request->input('attendee_application_form.birthdate')));
     $attendeeHealthReleaseFormData = array('gender' => $this->request->input('attendee_health_release_form.gender'), 'emg_contactname' => $this->request->input('attendee_health_release_form.emgcontactname'), 'emg_contactrel' => $this->request->input('attendee_health_release_form.emgcontactrel'), 'emg_contactnumber' => $this->request->input('attendee_health_release_form.emgcontactnumber'), 'healthproblems' => $this->request->input('attendee_health_release_form.healthproblems'), 'allergies' => $this->request->input('attendee_health_release_form.allergies'), 'lasttetanusshot' => Carbon::parse($this->request->input('attendee_health_release_form.lasttetanusshot')), 'lastphysicalexam' => Carbon::parse($this->request->input('attendee_health_release_form.lastphysicalexam')), 'insurancecarrier' => $this->request->input('attendee_health_release_form.insurancecarrier'), 'insurancepolicynum' => $this->request->input('attendee_health_release_form.insurancepolicynum'), 'guardian_name' => $this->request->input('attendee_health_release_form.guardianfullname'), 'guardian_contact' => $this->request->input('attendee_health_release_form.guardian_phone'), 'guardian_relation' => $this->request->input('attendee_health_release_form.relationship'), 'guardian_sign' => $this->request->input('parent_signature'));
     $appForm = new AttendeeApplicationForm($attendeeApplicationFormData);
     $healthReleaseForm = new AttendeeHealthReleaseForm($attendeeHealthReleaseFormData);
     $eventRepo = new EventRepository();
     $event = $eventRepo->findById($eventId);
     $organizationRepo = new OrganizationRepository();
     $organization = $organizationRepo->findById($organizationId);
     $newAttendee = new Attendee($attendeeData);
     // Save new attendee
     $newAttendee = $newAttendee->create($attendeeData);
     $newAttendee->application_form()->save($appForm);
     $newAttendee->health_release_form()->save($healthReleaseForm);
     $newAttendee->save();
     if (!empty($newAttendee->id)) {
         try {
             $this->dispatch(new SendRegistrationConfirmation($newAttendee, $event));
         } catch (Exception $e) {
             Log::error('Could not process SendRegistrationConfirmation job.');
         }
     }
 }
 private function register($request)
 {
     $userRepository = new UserRepository();
     $organizationRepository = new OrganizationRepository();
     try {
         $organizationData = array('name' => $request->input('organization.name'));
         $userData = array('email' => $request->input('user.email'), 'firstname' => $request->input('user.firstname'), 'lastname' => $request->input('user.lastname'));
         $organization = $organizationRepository->createSubOrganization($organizationData);
         if ($organization) {
             $organizationAddress = new OrganizationInfo();
             $organizationAddress->email = $request->input('organizationinfo.email');
             $organizationAddress->address = $request->input('organizationinfo.address');
             $organizationAddress->city = $request->input('organizationinfo.city');
             $organizationAddress->state = $request->input('state');
             $organizationAddress->zipcode = $request->input('organizationinfo.zipcode');
             $organizationAddress->telephone = $request->input('organizationinfo.telephone');
             $organization->info()->save($organizationAddress);
             $user = $userRepository->make($userData);
             if ($organization->users()->save($user)) {
                 $user->assignRole(Role::ADMIN);
             }
         }
     } catch (Exception $e) {
         if (!is_null($organization)) {
             $organization->delete();
         }
         Log::error($e->getMessage());
         abort(500);
     }
     return $user;
 }
 public function testGetPartnerOrganizations()
 {
     $org = new Organization();
     $orgRepo = new OrganizationRepository($org);
     $partners = $orgRepo->getPartnerOrganizations(1);
     $partners = $partners->keyBy('name');
     $this->assertTrue($partners->has('Partner 1'));
     $this->assertFalse($partners->has('Fake'));
 }
 public function handle()
 {
     $organizationRepo = new OrganizationRepository();
     $organizationInfoRepo = new OrganizationInfoRepository();
     $organization = $organizationRepo->findById($this->organizationId);
     $orgInfo = $organization->info()->first();
     $orgData = array('name' => $this->request->input('name'));
     $orgInfoData = array('email' => $this->request->input('email'), 'address' => $this->request->input('address'), 'city' => $this->request->input('city'), 'state' => $this->request->input('state'), 'zipcode' => $this->request->input('zipcode'), 'telephone' => $this->request->input('telephone'));
     $organization->update($orgData);
     $orgInfo->update($orgInfoData);
 }
 private function updateEvent()
 {
     if ($this->request->hasFile('image')) {
         $extension = $this->request->file('image')->getClientOriginalExtension();
         $image_path = 'images/public/' . $this->banner_img_prefix . $this->event->id . '.' . $extension;
         // Set Image Path in DB
         $this->event->img_url = $image_path;
         $image_path = public_path() . '/' . $image_path;
         $thumbnail_path = 'images/public/' . $this->banner_thumbnail_prefix . $this->event->id . '.' . $extension;
         $thumbnail_path = public_path() . '/' . $thumbnail_path;
         // Delete any existing files first
         File::delete($thumbnail_path);
         File::delete($image_path);
         $banner = Image::make($this->request->file('image'))->save($image_path);
         $thumbnail = Image::make($this->request->file('image'))->resize(450, 300)->save($thumbnail_path);
     }
     $this->event->title = $this->request->input('event.title');
     $this->event->description = $this->request->input('event.description');
     $this->event->start_date = $this->request->input('event.start_date');
     $this->event->end_date = $this->request->input('event.end_date');
     $this->event->start_time = $this->request->input('event.start_time');
     $this->event->end_time = $this->request->input('event.end_time');
     $this->event->price = $this->request->input('event.cost');
     $this->event->capacity = $this->request->input('event.capacity');
     $this->event->private = $this->request->input('event_privacy') == 'private';
     $this->event->published = $this->publish;
     $this->event->save();
     // 2. Save Event Location Information
     $eventSite = $this->event->eventsite()->first();
     $eventSite->name = $this->request->input('eventsite.name');
     $eventSite->address = $this->request->input('eventsite.address');
     $eventSite->city = $this->request->input('eventsite.city');
     $eventSite->state = $this->request->input('eventsite.state');
     $eventSite->zipcode = $this->request->input('eventsite.zipcode');
     $eventSite->save();
     // 3. Detach all Partner Organizations set for this Event
     $orgRepo = new OrganizationRepository(new Organization());
     $partnerOrganizations = $orgRepo->getPartnerOrganizations($this->event->organization()->first()->id);
     foreach ($partnerOrganizations as $partnerOrg) {
         $this->event->partners()->detach($partnerOrg);
     }
     // 4. Add select Partner Organizations to the Event
     if (!is_null($this->request->input('partners'))) {
         foreach ($this->request->input('partners') as $selectedPartners) {
             $partner = PartnerOrganization::find($selectedPartners);
             $this->event->partners()->attach($partner);
         }
     }
 }