public void DeletePhoto(string id) { using (DataAcess data = new DataAcess()) { data.DeletePhoto(int.Parse(id)); } }
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(); } }
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; } } }
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; } } }
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); }
public PhotoItem[] GetPhotos() { using (DataAcess data = new DataAcess()) { var photos = data.GetPhotos(); return photos.ToArray(); } }