private void CreateResume(Candidate candidate, Resume resume, FileReference fileReference) { // Create the file reference is needed. var resumeFileReference = fileReference == null ? null : CreateResumeFileReference(candidate.Id, fileReference.Id); var existingResumeId = candidate.ResumeId; if (existingResumeId == null) { // Create the resume. _resumesCommand.CreateResume(resume); candidate.ResumeId = resume.Id; // Add the resume to the candidate. _repository.AddResume(candidate.Id, resume.Id, resumeFileReference == null ? (Guid?)null : resumeFileReference.Id); } else { // Update the resume. var existingResume = _resumesQuery.GetResume(existingResumeId.Value); resume.Id = existingResumeId.Value; resume.CreatedTime = existingResume.CreatedTime; _resumesCommand.UpdateResume(resume); // Update the resume on the candidate. _repository.UpdateResume(candidate.Id, resume.Id, resumeFileReference == null ? (Guid?)null : resumeFileReference.Id); } // Fire events. var updatedHandlers = ResumeUpdated; if (updatedHandlers != null) { updatedHandlers(this, new ResumeUpdatedEventArgs(candidate.Id, candidate.ResumeId)); } if (candidate.ResumeId != null) { if (fileReference != null) { if (existingResumeId != null) { var handlers = ResumeReloaded; if (handlers != null) { handlers(this, new ResumeEventArgs(candidate.Id, resume.Id, false)); } } else { var handlers = ResumeUploaded; if (handlers != null) { handlers(this, new ResumeEventArgs(candidate.Id, resume.Id, true)); } } } else { var handlers = ResumeEdited; if (handlers != null) { handlers(this, new ResumeEventArgs(candidate.Id, resume.Id, existingResumeId == null)); } } } }