public static VIDEO_ATTACHMENT AddVideoAttachment(String filename, String description, String title, decimal?display_type, int recordType, decimal recordID, string sessionID, Stream file) { VIDEO_ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { VIDEO_ATTACHMENT d = new VIDEO_ATTACHMENT(); d.RECORD_TYPE = recordType; d.VIDEO_ID = recordID; // we might not have the record id when the attaachment is created d.FILE_NAME = filename; d.DESCRIPTION = description; d.ATTACHMENT_TYPE_ID = recordType.ToString(); //To-do: what do we do when company_id is not set, like when they choose this // from the Business Org master screen? d.UPLOADED_ID = SessionManager.UserContext.Person.PERSON_ID; d.UPLOADED_DT = WebSiteCommon.CurrentUTCTime(); d.TITLE = title; //d.ATTACHMENT_SCOPE = docScope; d.SESSION_ID = sessionID; if (display_type.HasValue) { d.DISPLAY_TYPE = display_type.Value; } if (d.VIDEO_ATTACHMENT_FILE == null) { d.VIDEO_ATTACHMENT_FILE = new VIDEO_ATTACHMENT_FILE(); } //read in the file contents if (file != null) { file.Seek(0, SeekOrigin.Begin); byte[] bytearray = new byte[file.Length]; int count = 0; while (count < file.Length) { bytearray[count++] = Convert.ToByte(file.ReadByte()); } d.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA = bytearray; d.FILE_SIZE = file.Length; } // d.DISPLAY_TYPE = Path.GetExtension(filename); entities.AddToVIDEO_ATTACHMENT(d); entities.SaveChanges(); ret = d; } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }