Beispiel #1
0
        public static DOCUMENT Add(String filename, String description, decimal?display_type, string docScope, decimal recordID, Stream file)
        {
            DOCUMENT ret = null;

            try
            {
                using (PSsqmEntities entities = new PSsqmEntities())
                {
                    DOCUMENT d = new DOCUMENT();
                    d.FILE_NAME = filename;
                    d.FILE_DESC = description;

                    //To-do: what do we do when company_id is not set, like when they choose this
                    //       from the Business Org master screen?
                    d.COMPANY_ID     = SessionManager.EffLocation.Company.COMPANY_ID;
                    d.OWNER_ID       = SessionManager.UserContext.Person.PERSON_ID;
                    d.RECORD_ID      = recordID;
                    d.UPLOADED_BY    = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME;
                    d.UPLOADED_DT    = WebSiteCommon.CurrentUTCTime();
                    d.LANGUAGE_ID    = (int)SessionManager.UserContext.Person.PREFERRED_LANG_ID;
                    d.DOCUMENT_SCOPE = docScope;
                    if (display_type.HasValue)
                    {
                        d.DISPLAY_TYPE = display_type.Value;
                    }

                    if (d.DOCUMENT_FILE == null)
                    {
                        d.DOCUMENT_FILE = new DOCUMENT_FILE();
                    }

                    //read in the file contents
                    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.DOCUMENT_FILE.DOCUMENT_DATA = bytearray;
                    d.FILE_SIZE = file.Length;

                    // d.DISPLAY_TYPE = Path.GetExtension(filename);

                    entities.AddToDOCUMENT(d);
                    entities.SaveChanges();

                    ret = d;
                }
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
                ret = null;
            }

            return(ret);
        }