public bool AddAccount(ModelAccounts modelAccounts, int clientId) { try { using (SqlConnection connection = new SqlConnection(base.connString)) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { string sqlQuery = @"insert into Account ([IBAN] ,[Open_date] ,[Client_id]) values(@iban, @open, @clientId)"; SqlCommand commandAdd = new SqlCommand(sqlQuery, connection); commandAdd.Parameters.Add("@iban", SqlDbType.NVarChar).Value = modelAccounts.IBAN; commandAdd.Parameters.Add("@open", SqlDbType.DateTime).Value = modelAccounts.OpenDate; commandAdd.Parameters.Add("@clientId", SqlDbType.Int).Value = clientId; if (commandAdd.ExecuteNonQuery() > 0) { return(true); } } } } catch (Exception) { throw; } return(false); }
private void btnSaveClient_Click(object sender, EventArgs e) { newAccount = new LogicAccount().NewAccount(); randomAddress.Street = txtStreet.Text; randomAddress.City = txtCity.Text; randomAddress.PostalCode = txtPostCode.Text; randomClient.FirstName = txtName.Text; randomClient.LastName = txtSurname.Text; randomClient.IdentityCard = txtIdentityCard.Text; randomClient.PhoneNumber = txtPhone.Text; randomClient.Email = txtMail.Text; logicAccount.CreateBankClient(randomAddress, randomClient, newAccount); }
public ModelAccounts GenerateAccount() { string IbanGenerator() { StringBuilder iban = new StringBuilder(); iban.Append("SK"); Random random = new Random(); while (iban.Length < 24) { iban.Append($"{random.Next(0, 9)}"); } return(iban.ToString()); } ModelAccounts modelAccounts = new ModelAccounts() { IBAN = IbanGenerator(), OpenDate = DateTime.Now, }; return(modelAccounts); }
public bool CreateBankClient(ModelAddress modelAddress, ModelClient modelClient, ModelAccounts modelAccounts) { int addressId = new RepositoryAddress().AddAddress(modelAddress); if (addressId > 0) { int clientId = new RepositoryClient().AddClient(modelClient, addressId); if (clientId > 0) { return(new RepositoryAccount().AddAccount(modelAccounts, clientId)); } } return(false); }