|
1 |
| -public with sharing class CourseRegistrationController { |
| 1 | +public without sharing class CourseRegistrationController { |
2 | 2 | @AuraEnabled
|
3 | 3 | public static String createRegistration(String fields, String courseId) {
|
4 | 4 | try {
|
5 |
| - /* Boolean duplicate = checkForDuplicates( contactId, courseId ); |
6 |
| - if ( duplicate ) { return 'Du er allerede påmeldt dette kurset'; } |
7 |
| - insertRegistration( contactId, courseId );*/ |
| 5 | + Boolean duplicate = checkForDuplicates(fields, courseId ); |
| 6 | + if ( duplicate ) { |
| 7 | + return 'Du er allerede påmeldt dette kurset, vennligst bruk en annen e-postadresse.'; |
| 8 | + } |
8 | 9 | Boolean courseIsFull = checkIfCourseIsFull(courseId);
|
9 |
| - |
10 | 10 | if (fields != null) {
|
11 | 11 | insertRegistration(fields, courseId);
|
12 | 12 | }
|
13 | 13 | if (courseIsFull) {
|
14 | 14 | return 'Registrering vellykket! Du er nå satt på venteliste og vil motta bekreftelse på e-post dersom du blir tildelt en plass.';
|
15 | 15 | }
|
16 |
| - |
17 | 16 | return 'Påmelding vellykket. Du vil om kort tid motta en bekreftelse på e-post';
|
18 | 17 | } catch (Exception e) {
|
19 | 18 | return 'Det oppsto en feil. Prøv igjen senere.';
|
20 | 19 | }
|
21 | 20 | }
|
| 21 | + |
22 | 22 | @AuraEnabled
|
23 | 23 | public static Course__c getCourseFields(String courseId) {
|
24 | 24 | return [
|
@@ -86,17 +86,15 @@ public with sharing class CourseRegistrationController {
|
86 | 86 | insert registration;
|
87 | 87 | }
|
88 | 88 | }
|
89 |
| - |
90 |
| - /* |
91 |
| - public static Boolean checkForDuplicates( Id contactId, Id courseId ) { |
| 89 | + |
| 90 | + public static Boolean checkForDuplicates( String fields, Id courseId ) { |
| 91 | + CourseRegistrationModel model = CourseRegistrationModel.parse(fields); |
92 | 92 | List<CourseRegistration__c> existingRecord =
|
93 |
| - [SELECT Id, Course__c, CourseParticipant__c |
| 93 | + [SELECT Id, Course__c, CourseParticipant__r.Email |
94 | 94 | FROM CourseRegistration__c
|
95 | 95 | WHERE Course__c =: courseId
|
96 |
| - AND CourseParticipant__c =: contactId LIMIT 1]; |
97 |
| -
|
98 |
| - Boolean exists = existingRecord.size() > 0 ? true : false; |
| 96 | + AND CourseParticipant__r.Email =: model.email LIMIT 1]; |
99 | 97 |
|
100 |
| - return exists; |
101 |
| - }*/ |
| 98 | + return existingRecord.size() > 0; |
| 99 | + } |
102 | 100 | }
|
0 commit comments