public void CreateAccount_AccountExistsAndMatchesApplicationInfo(MembershipType membershipType) { membershipApplication = CreateAndRecordMembershipApplication(membershipType); Assert.NotNull(membershipApplication); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand($"SELECT COUNT(*) FROM AspNetUsers WHERE MemberName = '{membershipApplication.ProspectiveMemberContactInfo.FirstName} {membershipApplication.ProspectiveMemberContactInfo.LastName}'" + $" AND Email = '{membershipApplication.ProspectiveMemberContactInfo.Email}' AND PhoneNumber = '{membershipApplication.ProspectiveMemberContactInfo.PrimaryPhone}' AND" + $" MembershipType = '{membershipType.ToString()}'", connection)) { command.CommandType = System.Data.CommandType.Text; connection.Open(); Assert.Equal("0", command.ExecuteScalar().ToString()); } } bool confirmation = membershipApplication.CreateMemberAccount(out string message); Assert.True(confirmation); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand($"SELECT COUNT(*) FROM AspNetUsers WHERE MemberName = '{membershipApplication.ProspectiveMemberContactInfo.FirstName} {membershipApplication.ProspectiveMemberContactInfo.LastName}'" + $" AND Email = '{membershipApplication.ProspectiveMemberContactInfo.Email}' AND PhoneNumber = '{membershipApplication.ProspectiveMemberContactInfo.PrimaryPhone}'", connection)) { command.CommandType = System.Data.CommandType.Text; connection.Open(); Assert.Equal("1", command.ExecuteScalar().ToString()); } } }
public MembershipRule(MembershipType typeOfMembership) { this.typeOfMembership = typeOfMembership; match = "membership request " + typeOfMembership.ToString().ToLower(); }
private bool AssessMembsershipFees(Guid id, out string message) { bool confirmation = false; message = "Success"; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("AssessMembershipFees", connection) { CommandType = System.Data.CommandType.StoredProcedure }) { MemberFees fees = Activator.CreateInstance(typeof(MemberFees).Assembly.ToString(), $"TechnicalServices.Memberships.{MembershipType.ToString()}").Unwrap() as MemberFees; command.Parameters.AddWithValue("@feeDetails", fees.FeeDetails); command.Parameters.AddWithValue("@userId", id); command.Parameters.Add(new SqlParameter("@returnCode", -1) { Direction = System.Data.ParameterDirection.ReturnValue }); connection.Open(); try { command.ExecuteNonQuery(); confirmation = command.Parameters[command.Parameters.Count - 1].Value.ToString() == "0"; } catch (Exception ex) { message = ex.Message; confirmation = false; } } } return(confirmation); }
public bool CreateMemberAccount(out string message) { bool confirmation; message = "success"; Guid id = default; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("CreateMemberAccount", connection) { CommandType = System.Data.CommandType.StoredProcedure }) { command.Parameters.AddWithValue("@membershipType", MembershipType.ToString()); command.Parameters.AddWithValue("@lastName", ProspectiveMemberContactInfo.LastName); command.Parameters.AddWithValue("@firstName", ProspectiveMemberContactInfo.FirstName); command.Parameters.AddWithValue("@email", ProspectiveMemberContactInfo.Email); command.Parameters.AddWithValue("@phoneNumber", ProspectiveMemberContactInfo.PrimaryPhone); command.Parameters.AddWithValue("@passwordHash", new PasswordHasher().HashPassword(defaultPassword)); Random random = new Random(); StringBuilder securityStamp = new StringBuilder(); for (int i = 0; i < 32; i++) { char next = (char)random.Next('0', 'Z' + 1); while (next >= 58 && next <= 64) { next = (char)random.Next('0', 'Z' + 1); } securityStamp.Append(next); } command.Parameters.AddWithValue("@securityStamp", securityStamp.ToString()); command.Parameters.AddWithValue("@concurrencyStamp", Guid.NewGuid()); id = Guid.NewGuid(); command.Parameters.AddWithValue("id", id); command.Parameters.Add(new SqlParameter("@returnCode", -1) { Direction = System.Data.ParameterDirection.ReturnValue }); connection.Open(); try { command.ExecuteNonQuery(); confirmation = command.Parameters[command.Parameters.Count - 1].Value.ToString() == "0"; } catch (Exception ex) { confirmation = false; message = ex.Message; } } } confirmation = AssessMembsershipFees(id, out message); return(confirmation); }