private void Validate(Guid employerId, IEnumerable <Guid> existingAttachmentIds, FileContents fileContents, string fileName) { // Must have appropriate file extension. var extension = Path.GetExtension(fileName).ToLower(); if (!Constants.ValidFileExtensions.Contains(extension)) { throw new InvalidFileNameException { FileName = fileName, ValidFileExtensions = Constants.ValidFileExtensions } } ; // Must not be too large. if (fileContents.Length > Constants.MaxAttachmentFileSize) { throw new FileTooLargeException { MaxFileSize = Constants.MaxAttachmentFileSize } } ; // The total mmust not be too large. var attachments = _repository.GetMessageAttachments(employerId, existingAttachmentIds); if (attachments.Count > 0) { var fileReferences = _filesQuery.GetFileReferences(from a in attachments select a.FileReferenceId, new Range()); var totalSize = attachments.Sum(a => (from f in fileReferences where f.Id == a.FileReferenceId select f).Single().FileData.ContentLength); if (totalSize + fileContents.Length > Constants.MaxAttachmentTotalFileSize) { throw new TotalFilesTooLargeException { MaxTotalFileSize = Constants.MaxAttachmentTotalFileSize } } ; } } } }
IList <MemberMessageAttachment> IEmployerMemberContactsQuery.GetMessageAttachments(IEmployer employer, IEnumerable <Guid> ids) { return(employer == null ? new List <MemberMessageAttachment>() : _repository.GetMessageAttachments(employer.Id, ids)); }