Ejemplo n.º 1
0
        public void UploadPhoto(string fileName, string description, Stream fileContents)
        {
            byte[] buffer = new byte[32768];
            MemoryStream ms = new MemoryStream();
            int bytesRead, totalBytesRead = 0;
            do
            {
                bytesRead = fileContents.Read(buffer, 0, buffer.Length);
                totalBytesRead += bytesRead;

                ms.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);

            // Save the photo on database.
            using (DataAcess data = new DataAcess())
            {
                var photo = new Photo() { Name = fileName, Description = description, Data = ms.ToArray(), DateTime = DateTime.UtcNow };
                data.InsertPhoto(photo);
            }

            ms.Close();
            Console.WriteLine("Uploaded file {0} with {1} bytes", fileName, totalBytesRead);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Photos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotos(Photo photo)
 {
     base.AddObject("Photos", photo);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new Photo object.
 /// </summary>
 /// <param name="photoID">Initial value of the PhotoID property.</param>
 /// <param name="data">Initial value of the Data property.</param>
 /// <param name="dateTime">Initial value of the DateTime property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Photo CreatePhoto(global::System.Int32 photoID, global::System.Byte[] data, global::System.DateTime dateTime, global::System.String name)
 {
     Photo photo = new Photo();
     photo.PhotoID = photoID;
     photo.Data = data;
     photo.DateTime = dateTime;
     photo.Name = name;
     return photo;
 }
Ejemplo n.º 4
0
 public void InsertPhoto(Photo photo)
 {
     data.Photos.AddObject(photo);
     data.SaveChanges();
 }