public Int16 InsertIntoDatabase() { if (this.created == true) { using (SqlConnection connOne = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDBConnection"].ConnectionString.ToString())) { using (SqlCommand cmdOne = new SqlCommand("InsertBlackList", connOne)) { Int16 result = 0; CustomerClass tmpClass = new CustomerClass(); tmpClass = tmpClass.SelectOneCustomer(this.CustomerID); tmpClass.generateEncryptor(this.CustomerName); cmdOne.CommandType = CommandType.StoredProcedure; cmdOne.Parameters.AddWithValue("@endedAt", this.EndedAt); cmdOne.Parameters.AddWithValue("@reason", this.Reason); cmdOne.Parameters.AddWithValue("@customerId", this.CustomerID); cmdOne.Parameters.AddWithValue("@customerName", tmpClass.generateEncryptor(this.CustomerName)); try { connOne.Open(); result = (Int16)cmdOne.ExecuteNonQuery(); if (result != 1) { throw new NullReferenceException(); } result = tmpClass.UpdateCustomerStatus(tmpClass.ID, tmpClass.Email, "blackListedStatus", true); } catch (SqlException err) { Console.WriteLine(err); result = -3; } catch (NullReferenceException) { result = -3; } catch (OverflowException) { result = -2; } catch { result = -1; } finally { connOne.Close(); } return(result); } } } else { return(0); } }
public Int16 UpdateCustomer(Guid ID, String PastEmail, String firstName, String lastName, String email, String PhoneNumber, DateTime dateOfBirth) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDBConnection"].ConnectionString.ToString())) { Int16 result = 0; CustomerClass tmpClass = new CustomerClass(); tmpClass = tmpClass.SelectOneCustomer(PastEmail); using (SqlCommand cmd = new SqlCommand("UpdateCustomerParticulars", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", ID); cmd.Parameters.AddWithValue("@PastEmail", PastEmail); cmd.Parameters.AddWithValue("@FirstName", tmpClass.generateEncryptor(firstName)); cmd.Parameters.AddWithValue("@LastName", tmpClass.generateEncryptor(lastName)); cmd.Parameters.AddWithValue("@NewEmail", email); cmd.Parameters.AddWithValue("@PhoneNumber", tmpClass.generateEncryptor(PhoneNumber)); cmd.Parameters.AddWithValue("@BirthDate", tmpClass.generateEncryptor(dateOfBirth.ToString())); try { conn.Open(); BlackListClass tmpPower = new BlackListClass(); result = tmpPower.UpdateBlacklistEmails(PastEmail, email); if (result < 0) { throw new OverflowException(); } result = (Int16)cmd.ExecuteNonQuery(); if (result != 1) { throw new OverflowException(); } if (email != PastEmail) { result = UpdateCustomerStatus(ID, PastEmail, "emailStatus", false); } } catch (SqlException err) { Console.WriteLine(err); result = -3; } catch (OverflowException err) { result = -2; } catch { result = -1; } finally { conn.Close(); } return(result); } } }