public void DeleteEntity(IEntity param) { SimpleEntity entity = param as SimpleEntity; if (entity == null) { throw new Exception("Entity is null at RefModel.cs"); } if (_connection.State != System.Data.ConnectionState.Closed) { throw new Exception("_connection is not in Closed state!!!"); } _connection.Open(); SqlCeCommand command = _connection.CreateCommand(); command.CommandText = String.Format("DELETE FROM {0} WHERE ID={1}", this.TableName, entity.ID); command.ExecuteNonQuery(); _connection.Close(); }
void AddNewRecord(object parameter) { if (String.IsNullOrEmpty(NewRecordName)) { return; } NewRecordName = NewRecordName.Trim(); SimpleEntity e = new SimpleEntity() { Name = NewRecordName }; int id = EntitiesDatabaseDirectory.InsertEntity(e); // we need to set last inserted id to the collection item Entities.Add(new EntityViewModel(e) { ID = id }); NewRecordName = ""; // eg clear textbox... RaisePropertyChanged("AddNewRecordName"); }
void AddNewRecord(object parameter) { if (String.IsNullOrEmpty(NewRecordName)) return; NewRecordName = NewRecordName.Trim(); SimpleEntity e = new SimpleEntity() { Name = NewRecordName }; int id = EntitiesDatabaseDirectory.InsertEntity(e); // we need to set last inserted id to the collection item Entities.Add(new EntityViewModel(e) { ID = id }); NewRecordName = ""; // eg clear textbox... RaisePropertyChanged("AddNewRecordName"); }