/// <summary> /// Creates a new customer record. /// </summary> /// <param name="newCustomer">The customer intence.</param> /// <returns>The number of effected records.</returns> /// <exception cref="System.Data.SqlClient.SqlException"> /// An exception occurred while executing the command against a locked row. This exception is /// not generated when you are using Microsoft .NET Framework version 1.0. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The object is disposed. /// </exception> public int Create(Poco::ICustomer newCustomer) { if (!this.IsDisposed) { return this._customer.Create(newCustomer); } else { throw new ObjectDisposedException("Bll.Customer class object is already disposed."); } }
/// <summary> /// Creates a new customer record. /// </summary> /// <param name="newCustomer">The customer intence.</param> /// <returns>The number of effected records.</returns> /// <exception cref="System.Data.SqlClient.SqlException"> /// An exception occurred while executing the command against a locked row. This exception is /// not generated when you are using Microsoft .NET Framework version 1.0. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The object is disposed. /// </exception> public int Create(Poco::ICustomer newCustomer) { if (!this.IsDisposed) { SqlParameter[] parameters = GetParameters(newCustomer); StringBuilder insertCommand = GetInsertCommand(); int effectedRecords = this._common.ExecuteNonQuery(insertCommand.ToString(), parameters); return effectedRecords; } else { throw new ObjectDisposedException("Dal.Customer object is already disposed."); } }
private static SqlParameter[] GetParameters(Poco::ICustomer newCustomer) { SqlParameter customerIdParameter = new SqlParameter("@CustomerID", SqlDbType.NChar, 5) { Value = newCustomer.CustomerId != null ? newCustomer.CustomerId : string.Empty, Direction = ParameterDirection.Input }; SqlParameter companyNameParameter = new SqlParameter("@CompanyName", SqlDbType.NVarChar, 40) { Value = newCustomer.CompanyName != null ? newCustomer.CompanyName : string.Empty, Direction = ParameterDirection.Input }; SqlParameter contactNameParameter = new SqlParameter("@ContactName", SqlDbType.NVarChar, 30) { Value = newCustomer.ContactName != null ? newCustomer.ContactName : string.Empty, Direction = ParameterDirection.Input }; SqlParameter contactTitleParameter = new SqlParameter("@ContactTitle", SqlDbType.NVarChar, 30) { Value = newCustomer.ContactTitle != null ? newCustomer.ContactTitle : string.Empty, Direction = ParameterDirection.Input }; SqlParameter addressParameter = new SqlParameter("@Address", SqlDbType.NVarChar, 60) { Value = newCustomer.Address != null ? newCustomer.Address : string.Empty, Direction = ParameterDirection.Input }; SqlParameter cityParameter = new SqlParameter("@City", SqlDbType.NVarChar, 15) { Value = newCustomer.City != null ? newCustomer.City : string.Empty, Direction = ParameterDirection.Input }; SqlParameter regionParameter = new SqlParameter("@Region", SqlDbType.NVarChar, 15) { Value = newCustomer.Region != null ? newCustomer.Region : string.Empty, Direction = ParameterDirection.Input }; SqlParameter postalCodeParameter = new SqlParameter("@PostalCode", SqlDbType.NVarChar, 10) { Value = newCustomer.PostalCode != null ? newCustomer.PostalCode : string.Empty, Direction = ParameterDirection.Input }; SqlParameter countryParameter = new SqlParameter("@Country", SqlDbType.NVarChar, 15) { Value = newCustomer.Country != null ? newCustomer.Country : string.Empty, Direction = ParameterDirection.Input }; SqlParameter phoneParameter = new SqlParameter("@Phone", SqlDbType.NVarChar, 24) { Value = newCustomer.Phone != null ? newCustomer.Phone : string.Empty, Direction = ParameterDirection.Input }; SqlParameter faxParameter = new SqlParameter("@Fax", SqlDbType.NVarChar, 24) { Value = newCustomer.Fax != null ? newCustomer.Fax : string.Empty, Direction = ParameterDirection.Input }; SqlParameter[] parameters = { customerIdParameter, companyNameParameter, contactNameParameter, contactTitleParameter, addressParameter, cityParameter, countryParameter, postalCodeParameter, phoneParameter, faxParameter, regionParameter }; return parameters; }