示例#1
0
 public void DeletePhoto(string id)
 {
     using (DataAcess data = new DataAcess())
     {
         data.DeletePhoto(int.Parse(id));
     }
 }
示例#2
0
        public PhotoItem[] GetPhotos()
        {
            using (DataAcess data = new DataAcess())
            {
                var photos = data.GetPhotos();
                List<PhotoItem> ret = new List<PhotoItem>();
                foreach (var photo in photos)
                    ret.Add(new PhotoItem() { PhotoID = photo.PhotoID, Name = photo.Name, Description = photo.Description, UploadedOn = photo.DateTime });

                return ret.ToArray();
            }
        }
示例#3
0
 public Stream GetLastPhoto()
 {
     using (DataAcess data = new DataAcess())
     {
         // Retrieve the last taken photo.
         PhotoItem photo = data.GetLastPhoto();
         if (photo != null)
         {
             MemoryStream ms = new MemoryStream(photo.ImgFile);
             return ms;
         }
         else
         {
             return null;
         }
     }
 }
示例#4
0
 public Stream GePhoto(string id)
 {
     using (DataAcess data = new DataAcess())
     {
         // Retrieve the last taken photo.
         var photo = data.GetPhoto(int.Parse(id));
         if (photo != null)
         {
             MemoryStream ms = new MemoryStream(photo.ImgFile);
             return ms;
         }
         else
         {
             return null;
         }
     }
 }
示例#5
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);
        }
示例#6
0
        public PhotoItem[] GetPhotos()
        {
            using (DataAcess data = new DataAcess())
            {
                var photos = data.GetPhotos();

                return photos.ToArray();
            }
        }