/// <summary> /// Gets all DPublisher objects from the database. /// </summary> /// <param name="command">Command containing the get all query.</param> /// <returns>All dpublishers from the database.</returns> private IEnumerable <DPublisher> ToDPublisherList(IDbCommand command) { using (var reader = command.ExecuteReader()) { List <DPublisher> items = new List <DPublisher>(); while (reader.Read()) { var item = new DPublisher(); Map(reader, item); items.Add(item); } return(items); } }
/// <summary> /// Adds a DPublisher to the database. /// </summary> /// <param name="dComic">DComic with publisher to add.</param> private void AddDPublisher(DPublisher dPublisher) { using (var command = context.CreateCommand()) { command.CommandText = @"Select * From Publishers Where Publishers.name = @name"; command.AddParameter("name", dPublisher.Name); int?id = (int?)command.ExecuteScalar(); if (id != null) { dPublisher.Id = (int)id; } else { command.CommandText = @"Insert into Publishers (Name) " + "values (@name)" + "SELECT CAST(scope_identity() AS int);"; dPublisher.Id = (int)command.ExecuteScalar(); } } }
/// <summary> /// Maps a record to a DPublisher object. /// </summary> /// <param name="record">Record to bind.</param> /// <param name="dPublisher">DPublisher to bind to.</param> private void Map(IDataRecord record, DPublisher dPublisher) { dPublisher.Id = (int)record["ID"]; dPublisher.Name = (string)record["Name"]; }