public void Dispose() { // If we have a cached entity, it must be a POST request. if (cachedEntity != null) { // Get the new entity from the Entity Framework object state manager. ObjectStateEntry entry = this.context.ObjectStateManager.GetObjectStateEntry(cachedEntity); if (entry.State == System.Data.EntityState.Unchanged) { // Since the entity was created successfully, move the temp file into the // storage directory and rename the file based on the new entity key. File.Move(tempFile, imageFilePath + "image" + cachedEntity.PhotoId.ToString()); // Delete the temp file. File.Delete(tempFile); } else { // A problem must have occurred when saving the entity to the database, // so we should delete the entity and temp file. context.DeleteObject(cachedEntity); File.Delete(tempFile); throw new DataServiceException("An error occurred. The photo could not be saved."); } } }
public void Dispose() { // If we have a cached entity, it must be a POST request. if (cachedEntity != null) { string newImageFileName = imageFilePath + "image" + cachedEntity.PhotoId.ToString(); string newImageThumbnailName = imageFilePath + "image" + cachedEntity.PhotoId.ToString() + "_thumb"; // Get the new entity from the Entity Framework object state manager. ObjectStateEntry entry = this.context.ObjectStateManager.GetObjectStateEntry(cachedEntity); if (entry.State == System.Data.EntityState.Unchanged) { // Since the entity was created successfully, move the temp file into the // storage directory and rename the file based on the new entity key. File.Move(tempFile, newImageFileName); // Delete the temp file. File.Delete(tempFile); // Create a bitmap for the new image. Bitmap newImage = new Bitmap(newImageFileName); // Generate the 100px thumbnail of the image. Image thumbnail = newImage.GetThumbnailImage(100, 100, null, IntPtr.Zero); // Save the thumbnail. thumbnail.Save(newImageThumbnailName); } else { // A problem must have occurred when saving the entity to the database, // so we should delete the entity and temp file. context.DeleteObject(cachedEntity); File.Delete(tempFile); throw new DataServiceException("An error occurred. The photo could not be saved."); } } }