/// <summary> /// Loads the images. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data">The data.</param> /// <param name="refresh">if set to <c>true</c> [refresh].</param> public static bool LoadImages <T>(this T data, bool refresh = false) where T : BaseModel { try { foreach (var prop in data.GetType().GetProperties()) { if (prop.PropertyType == typeof(AssassinImage) && (refresh || prop.GetValue(data) == null)) { using (var ctx = new AssassinImageDataContext()) { var image = ctx.Set <AssassinImage>().FirstOrDefault(p => p.RelationId == data.Id && p.RelatedTypeDescription == data.TypeDiscriptor); if (image == null) { return(false); } prop.SetValue(data, image); ctx.DetachAllEntities(); } } } } catch { return(false); } return(true); }
public static void Save(this AssassinImage AssassinImage) { if (AssassinImage != null) { try { using (var ctx = new AssassinImageDataContext()) { if (!ctx.Set <AssassinImage>().Any(p => p.Id == AssassinImage.Id)) { ctx.Set <AssassinImage>().Add(AssassinImage); } else { ctx.Set <AssassinImage>().Update(AssassinImage); } ctx.SaveChanges(); ctx.DetachAllEntities(); } } catch (Exception e) { Debug.WriteLine(e); } } }
/// <summary> /// Deletes the specified quant image. /// </summary> /// <param name="AssassinImage">The quant image.</param> public static void Delete(this AssassinImage AssassinImage) { if (AssassinImage != null) { using (var ctx = new AssassinImageDataContext()) { if (ctx.Set <AssassinImage>().Any(p => p.Id == AssassinImage.Id)) { ctx.Set <AssassinImage>().Remove(AssassinImage); ctx.SaveChanges(); ctx.DetachAllEntities(); } } } }