public bool UpdateUserMaterial(UserMaterial instance) { try { var userMaterial = Db.UserMaterials.Find(instance.UserMaterialId); var type = instance.GetType(); foreach(var info in type.GetProperties()) { if(info.CanWrite) { var value = info.GetValue(instance); if(value != null) { info.SetValue(userMaterial, value, null); } } } Db.SaveChanges(); return true; } catch { return false; } }
public bool CreateUserMaterial(UserMaterial instance) { try { if (instance.UserMaterialId != 0) return false; Db.UserMaterials.Add(instance); Db.SaveChanges(); return true; } catch { return true; } }