public void AddToT_Photo(T_Photo t_Photo) { base.AddObject("T_Photo", t_Photo); }
private T_Photo UploadPhoto(FileStream fileStream, string fileExtension) { EntityDescriptor entity = null; T_Photo p = new T_Photo(); p.ContentType = "image/" + fileExtension; CalligraphyEditor.App.Entities.AddToT_Photo(p); BitmapImage imageFromStream = new BitmapImage(); imageFromStream.BeginInit(); imageFromStream.StreamSource = fileStream; imageFromStream.CacheOption = BitmapCacheOption.OnLoad; imageFromStream.EndInit(); p.Width = imageFromStream.Width; p.Height = imageFromStream.Height; p.FileSize = fileStream.Length; fileStream.Seek(0, SeekOrigin.Begin); CalligraphyEditor.App.Entities.SetSaveStream(p, fileStream, true, p.ContentType, GetSafeFileName(fileStream.Name)); try { var response = CalligraphyEditor.App.Entities.SaveChanges().FirstOrDefault() as ChangeOperationResponse; if (p.ID == 0) { if (response != null) { entity = response.Descriptor as EntityDescriptor; } // Verify that the entity was created correctly. if (entity != null && entity.EditLink != null) { // Cache the current merge option (we reset to the cached // value in the finally block). MergeOption mergeOption = CalligraphyEditor.App.Entities.MergeOption; try { // Set the merge option so that server changes win. CalligraphyEditor.App.Entities.MergeOption = MergeOption.OverwriteChanges; // Get the updated entity from the service. // Note: we need Count() just to execute the query. CalligraphyEditor.App.Entities.Execute<T_Photo>(entity.EditLink).Count(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } finally { CalligraphyEditor.App.Entities.MergeOption = mergeOption; } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } return p; }
public static T_Photo CreateT_Photo(int ID) { T_Photo t_Photo = new T_Photo(); t_Photo.ID = ID; return t_Photo; }