Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public PageReference nominate()
- {
- try {
- // check to see if anyone else has already nominated someone with this email addres in this same year
- Application__c application = [select Id from Application__c where Nomination_Round__r.Grant_Round__c = :NominationRound.Grant_Round__c and email__c = :newapplicant.Email__c limit 1];
- // if so make a second instead of an application
- Second__c Second = new Second__c();
- Second.Nominator__c = NominationRound.Id;
- Second.Application__c = application.Id;
- insert Second;
- PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name+'&second=true');
- pageRef.setRedirect(true);
- return pageRef;
- } catch (exception e) {
- // if not already nominated
- // check if contact wtih same email address exists
- try {
- applicant = [select Id from Contact where email = :newapplicant.Email__c limit 1];
- } catch (exception f) {
- Applicant = new Contact();
- }
- // update contact
- Applicant.LastName = newapplicant.Last_Name__c;
- Applicant.FirstName = newapplicant.First_Name__c;
- Applicant.npe01__HomeEmail__c = newapplicant.Email__c;
- Applicant.npe01__Preferred_Email__c = 'Personal';
- upsert Applicant;
- // create new application and related contact with it
- newapplicant.applicant__c = Applicant.id;
- newapplicant.nomination_type__c = 'Nominee';
- if already nominated 2 or more make this one an alternate vs regular nominee
- try {
- List <Application__c> totalApplications = getApplications();
- if (totalApplications.size() >= 2){
- newapplicant.nomination_type__c = 'Alternate';
- NominationRound.Completed_Nominations__c = true;
- }
- } catch (exception f) {
- }
- insert newapplicant;
- PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name);
- pageRef.setRedirect(true);
- return pageRef;
- }
- }
- // if they say they are done before submitting 3 nominees
- public PageReference completedNomations()
- {
- NominationRound.Completed_Nominations__c = true;
- upsert NominationRound;
- PageReference pageRef = pageRef = new PageReference('/nominate?id='+NominationRound.id+'&key='+NominationRound.name);
- pageRef.setRedirect(true);
- return pageRef;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement