/// <summary>
        /// Save a new or existing catalogue in the database
        /// </summary>
        /// <param name="file">File to be saved in the document</param>
        /// <param name="documentId">Document identifier</param>
        /// <param name="description">Document description</param>
        /// <param name="userName">Name of logged user</param>
        /// <param name="serviceOrderId">Service order idenfier</param>
        public static void SaveDocument(CuteWebUI.MvcUploadFile file, Guid? documentId, string description, string userName, Guid serviceOrderId)
        {
            Document documentNewEdit = null;
            using (VestalisEntities context = new VestalisEntities())
            {
                //if the entity don't have a catalogue id, the system will perform insert operation
                //otherwise, the system will perform edit operation
                if (documentId == Guid.Empty)
                {
                    documentNewEdit = new Document();
                    documentNewEdit.DocumentId = Guid.NewGuid();
                    documentNewEdit.ServiceOrderId = serviceOrderId;
                    //set auditory fields
                    documentNewEdit.CreationBy = userName;
                    documentNewEdit.CreationDate = DateTime.UtcNow;
                    documentNewEdit.DocumentDescription = description;
                    documentNewEdit.DocumentName = file.FileName;
                    //Copy the document to the entity
                    using (Stream fileStream = file.OpenStream())
                    {
                        byte[] buffer = new byte[fileStream.Length];
                        fileStream.Position = 0;
                        fileStream.Read(buffer, 0, (int)fileStream.Length);
                        documentNewEdit.DocumentFile = buffer;

                    }
                    context.Documents.AddObject(documentNewEdit);
                }
                else
                {
                    //get the current catalogue to edit
                    documentNewEdit = context.Documents
                    .FirstOrDefault(data => data.IsDeleted == false && data.DocumentId == documentId);

                    //set the description entered by the user
                    documentNewEdit.DocumentDescription = description;
                    //set auditory fields
                    documentNewEdit.ModificationBy = userName;
                    documentNewEdit.ModificationDate = DateTime.UtcNow;
                }

                //save changes
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Create a new Document object.
 /// </summary>
 /// <param name="documentId">Initial value of the DocumentId property.</param>
 /// <param name="creationBy">Initial value of the CreationBy property.</param>
 /// <param name="creationDate">Initial value of the CreationDate property.</param>
 /// <param name="isDeleted">Initial value of the IsDeleted property.</param>
 public static Document CreateDocument(global::System.Guid documentId, global::System.String creationBy, global::System.DateTime creationDate, global::System.Boolean isDeleted)
 {
     Document document = new Document();
     document.DocumentId = documentId;
     document.CreationBy = creationBy;
     document.CreationDate = creationDate;
     document.IsDeleted = isDeleted;
     return document;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Documents EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDocuments(Document document)
 {
     base.AddObject("Documents", document);
 }
Beispiel #4
0
 /// <summary>
 /// Get an instance of DocumentModel
 /// </summary>
 public DocumentModel()
 {
     Links = new List<string>();
     Document = new Document();
 }