public static ASC.Files.Core.File GetInvoicePdfExistingOrCreate(ASC.CRM.Core.Entities.Invoice invoice) { var existingFile = invoice.GetInvoiceFile(); if (existingFile != null) { return existingFile; } else { var newFile = PdfCreator.CreateFile(invoice); invoice.FileID = Int32.Parse(newFile.ID.ToString()); Global.DaoFactory.GetInvoiceDao().UpdateInvoiceFileID(invoice.ID, invoice.FileID); Global.DaoFactory.GetRelationshipEventDao().AttachFiles(invoice.ContactID, invoice.EntityType, invoice.EntityID, new[] { invoice.FileID }); return newFile; } }