public PropertyBase PropertyPhotoAdd(PhotoAdd newItem)
{
// Validate the associated item
var a = ds.Properties.Find(newItem.PropertyId);
if (a == null)
{
return null;
}
else
{
// Attempt to add the new item
var addedItem = new Photo();
ds.Photos.Add(addedItem);
addedItem.Caption = newItem.Caption;
addedItem.Property = a;
// Handle the uploaded photo...
// First, extract the bytes from the HttpPostedFile object
byte[] photoBytes = new byte[newItem.PhotoUpload.ContentLength];
newItem.PhotoUpload.InputStream.Read(photoBytes, 0, newItem.PhotoUpload.ContentLength);
// Then, configure the new object's properties
addedItem.Content = photoBytes;
addedItem.ContentType = newItem.PhotoUpload.ContentType;
ds.SaveChanges();
return (addedItem == null) ? null : Mapper.Map<PropertyBase>(a);
}
}