Would like to Modify the Commerce Kits Register Page, so that it can request additional
information. I modified and adjusted the CMRC_ CustomerAdd, & also the CMRC_Customer Details stored procedures. And I adjusted the CustomersDB.cs file. listed also below, but I get an error message when I try to compile a new ASPNETCommerce.dll. Don't know what I'm missing/overlooking. I've only added 1 Item to the orininal CustomersDB.cs file, and that is the "FirstName' . I would like to add additional names later, but for now I just want to be able to modify it with just one Item. But I'm over looking something. If anyone can Help, That would be most welcome TIA.
CustomerDB.cs<142,40>: error CS0103: The name ?FirstName? does not exist in the class or namespace ?ASPNET.StarterKit.Commerce.CustomersDB?
CREATE Procedure CMRC_CustomerAdd
(
@FullName nvarchar(50),
@Email nvarchar(50),
@Password nvarchar(50),
@FirstName nvarchar(50),
@CustomerID int OUTPUT
)
AS
INSERT INTO CMRC_Customers
(
FullName,
EmailAddress,
Password,
FirstName
)
VALUES
(
@FullName,
@Email,
@Password,
@FirstName
)
SELECT
@CustomerID = @@Identity
GO
CREATE Procedure CMRC_CustomerDetail
(
@CustomerID int,
@FullName nvarchar(50) OUTPUT,
@Email nvarchar(50) OUTPUT,
@Password nvarchar(50) OUTPUT,
@FirstName nvarchar(50) OUTPUT
)
AS
SELECT
@FullName = FullName,
@Email = EmailAddress,
@Password = Password,
@FirstName = FirstName
FROM
CMRC_Customers
WHERE
CustomerID = @CustomerID
GO
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace ASPNET.StarterKit.Commerce {
//*******************************************************
//
// CustomerDetails Class
//
// A simple data class that encapsulates details about
// a particular customer inside the Commerce Customer
// database.
//
//*******************************************************
public class CustomerDetails {
public String FullName;
public String Email;
public String Password;
public String FirstName;
}
//*******************************************************
//
// CustomersDB Class
//
// Business/Data Logic Class that encapsulates all data
// logic necessary to add/login/query customers within
// the Commerce Customer database.
//
//*******************************************************
public class CustomersDB {
//*******************************************************
//
// CustomersDB.GetCustomerDetails() Method <a name="GetCustomerDetails"></a>
//
// The GetCustomerDetails method returns a CustomerDetails
// struct that contains information about a specific
// customer (name, email, password, etc).
//
// Other relevant sources:
// +
CustomerDetail Stored Procedure
//
//*******************************************************
public CustomerDetails GetCustomerDetails(String customerID)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("CMRC_CustomerDetail", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
parameterCustomerID.Value = Int32.Parse(customerID);
myCommand.Parameters.Add(parameterCustomerID);
SqlParameter parameterFullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
parameterFullName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterFullName);
SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
parameterEmail.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterEmail);
SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
parameterPassword.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterFirstName = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
parameterFirstName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterFirstName);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
// Create CustomerDetails Struct
CustomerDetails myCustomerDetails = new CustomerDetails();
// Populate Struct using Output Params from SPROC
myCustomerDetails.FullName = (string)parameterFullName.Value;
myCustomerDetails.Password = (string)parameterPassword.Value;
myCustomerDetails.Email = (string)parameterEmail.Value;
myCustomerDetails.FirstName = (string)parameterFirstName.Value;
return myCustomerDetails;
}
//*******************************************************
//
// CustomersDB.AddCustomer() Method <a name="AddCustomer"></a>
//
// The AddCustomer method inserts a new customer record
// into the customers database. A unique "CustomerId"
// key is then returned from the method. This can be
// used later to place orders, track shopping carts,
// etc within the ecommerce system.
//
// Other relevant sources:
// +
CustomerAdd Stored Procedure
//
//*******************************************************
public String AddCustomer(string fullName, string email, string password, string firstname)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("CMRC_CustomerAdd", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterFullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
parameterFullName.Value = fullName;
myCommand.Parameters.Add(parameterFullName);
SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
parameterEmail.Value = email;
myCommand.Parameters.Add(parameterEmail);
SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
parameterPassword.Value = password;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterFirstName = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
parameterFirstName.Value = FirstName;
myCommand.Parameters.Add(parameterFirstName);
SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
parameterCustomerID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterCustomerID);
try {
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
// Calculate the CustomerID using Output Param from SPROC
int customerId = (int)parameterCustomerID.Value;
return customerId.ToString();
}
catch {
return String.Empty;
}
}
//*******************************************************
//
// CustomersDB.Login() Method <a name="Login"></a>
//
// The Login method validates a email/password pair
// against credentials stored in the customers database.
// If the email/password pair is valid, the method returns
// the "CustomerId" number of the customer. Otherwise
// it will throw an exception.
//
// Other relevant sources:
// +
CustomerLogin Stored Procedure
//
//*******************************************************
public String Login(string email, string password)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("CMRC_CustomerLogin", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
parameterEmail.Value = email;
myCommand.Parameters.Add(parameterEmail);
SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
parameterPassword.Value = password;
myCommand.Parameters.Add(parameterPassword);
SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
parameterCustomerID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterCustomerID);
// Open the connection and execute the Command
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
int customerId = (int)(parameterCustomerID.Value);
if (customerId == 0) {
return null;
}
else {
return customerId.ToString();
}
}
}
}