/// <summary>
 /// Save the picture in the database
 /// </summary>
 /// <param name="file">File uploaded by the user</param>
 /// <param name="userName">User name logged in the application</param>
 /// <param name="serviceOrderReportId">Service order identifier related</param>
 /// <param name="inspectionReportItemId">Id of inspections report item</param>
 public static void UploadPicture(CuteWebUI.MvcUploadFile file, Guid serviceOrderReportId, string userName, Guid? inspectionReportItemId = null)
 {
     //Add the file to DB along with metadata
     using (VestalisEntities context = new VestalisEntities())
     {
         //Create a new picture
         Picture picture = new Picture();
         picture.PictureId = Guid.NewGuid();
         picture.ServiceOrderId = serviceOrderReportId;
         if (inspectionReportItemId.HasValue)
             picture.InspectionReportItemId = inspectionReportItemId;
         //Copy document to entity
         using (Stream fileStream = file.OpenStream())
         {
             byte[] buffer = new byte[fileStream.Length];
             fileStream.Position = 0;
             fileStream.Read(buffer, 0, (int)fileStream.Length);
             picture.PictureFile = buffer;
             //Resize the thumbnail picture
             Image imageInput = Image.FromStream(fileStream);
             Image thumbnailImage = ResizeImage(imageInput, new Size(200, 200));
             ImageConverter converter = new ImageConverter();
             byte[] byteArrayThumb = (byte[])converter.ConvertTo(thumbnailImage, typeof(byte[]));
             //Set the thumbnail image to save in the database
             picture.PictureFileThumbnail = byteArrayThumb;
         }
         picture.CreationBy = userName;
         picture.CreationDate = DateTime.UtcNow;
         context.Pictures.AddObject(picture);
         //Save the new picture
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Create a new Picture object.
 /// </summary>
 /// <param name="pictureId">Initial value of the PictureId property.</param>
 /// <param name="pictureFile">Initial value of the PictureFile 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 Picture CreatePicture(global::System.Guid pictureId, global::System.Byte[] pictureFile, global::System.String creationBy, global::System.DateTime creationDate, global::System.Boolean isDeleted)
 {
     Picture picture = new Picture();
     picture.PictureId = pictureId;
     picture.PictureFile = pictureFile;
     picture.CreationBy = creationBy;
     picture.CreationDate = creationDate;
     picture.IsDeleted = isDeleted;
     return picture;
 }
        /// <summary>
        /// Save the picture in the database
        /// </summary>
        /// <param name="file">File uploaded by the user</param>
        /// <param name="userName">User name logged in the application</param>
        /// <param name="serviceOrderReportId">Service order identifier related</param>
        public static void UploadDocument(CuteWebUI.MvcUploadFile file, Guid serviceOrderReportId, string userName)
        {
            //Add the file to DB along with metadata
            using (VestalisEntities context = new VestalisEntities())
            {
                //Create a new picture
                Picture picture = new Picture();
                picture.PictureId = Guid.NewGuid();
                picture.ServiceOrderId = serviceOrderReportId;
                //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);
                    picture.PictureFile = buffer;

                }
                picture.CreationBy = userName;
                picture.CreationDate = DateTime.UtcNow;
                context.Pictures.AddObject(picture);
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Pictures EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPictures(Picture picture)
 {
     base.AddObject("Pictures", picture);
 }