/// <summary> /// class that attempts to add a person object taken from a post request and add them in to the /// uses standard c# commiaction setup with stored procedure to do this /// </summary> /// <param name="incommingPerson"></param> /// <returns>if successful or not </returns> public bool AddPersonToPeople(CustomerDOO incommingPerson) { //create connection object(to be setup in config file in future) SqlConnection connection = new SqlConnection(sb.ConnectionString); //create blank sql command SqlCommand cmd = new SqlCommand() { Connection = connection, CommandText = "SPaddNewCustomer" }; connection.Open(); using (connection) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("email", incommingPerson.Email) { Direction = System.Data.ParameterDirection.Input, DbType = System.Data.DbType.String }); cmd.Parameters.Add(new SqlParameter("firstName", incommingPerson.FirstName) { Direction = System.Data.ParameterDirection.Input, DbType = System.Data.DbType.String }); cmd.Parameters.Add(new SqlParameter("lastName", incommingPerson.LastName) { Direction = System.Data.ParameterDirection.Input, DbType = System.Data.DbType.String }); cmd.Parameters.Add(new SqlParameter("address", incommingPerson.Address) { Direction = System.Data.ParameterDirection.Input, DbType = System.Data.DbType.String }); cmd.Parameters.Add(new SqlParameter("postcode", incommingPerson.Postcode) { Direction = System.Data.ParameterDirection.Input, DbType = System.Data.DbType.String }); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { connection.Close(); return(false); } } connection.Close(); return(true); }
public bool Post(CustomerDOO val) { return(sQL.AddPersonToPeople(val)); }