public void Create(Bullet bullet) { using (var connection = SqlConnectionFactory.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = SqlScripts.Bullet_Create; AddParameters(bullet, command); connection.Open(); bullet.Id = (int)command.ExecuteScalar(); } }
public void Import(Bullet bullet) { using (var connection = SqlConnectionFactory.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = SqlScripts.Bullet_Import; AddParameters(bullet, command); command.Parameters.Add(new SqlParameter("@id", bullet.Id)); connection.Open(); command.ExecuteNonQuery(); } }
public Bullet CreateBullet(int id = 0, int pageId = 0) { var result = new Bullet { Id = id, Text = string.Format("Unit test bullet text - {0}.", _bulletCount), HorizontalOffset = 20, VerticalOffset = 20, OffsetElementId = "TestBulletOffsetElementId", Number = 1, PageId = pageId, }; _bulletCount++; return result; }
private static void AddParameters(Bullet bullet, SqlCommand command) { command.Parameters.AddRange(new SqlParameter[] { new SqlParameter("@pageId", bullet.PageId), new SqlParameter("@number", bullet.Number), new SqlParameter("@text", bullet.Text), new SqlParameter("@verticalOffset", bullet.VerticalOffset), new SqlParameter("@horizontalOffset", bullet.HorizontalOffset), new SqlParameter("@offsetElementId", bullet.OffsetElementId), }); }