public async Task <int> CreateCustomerAsync() { using (var con = SqlClientModel.GetNewSqlConnection()) using (var command = new SqlCommand("INSERT INTO Customers(FirstName, LastName, MiddleName, DateOfBirth, DocumentNumber) " + "Values(@FirstName, @LastName, @MiddleName, @DateOfBirth, @DocumentNumber)", con)) { try { command.Parameters.AddWithValue("@FirstName", this.FirstName); command.Parameters.AddWithValue("@LastName", this.LastName); command.Parameters.AddWithValue("@MiddleName", this.MiddleName); command.Parameters.AddWithValue("@DateOfBirth", this.DateOfBirth); command.Parameters.AddWithValue("@DocumentNumber", this.DocumentNumber); await con.OpenAsync(); var result = await command.ExecuteNonQueryAsync(); return(result); } catch (Exception ex) { Console.WriteLine($"Customer adding fail - {ex.Message}"); } finally { con.Close(); } } return(0); }
static void Main(string[] args) { while (isWorking) { switch (ShowCustomerMenu()) { case "1": { Console.Clear(); int run; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{new string('-', 5)}Login Menu{new string('-', 5)}"); Console.ForegroundColor = ConsoleColor.White; Console.Write("(1) Sign in as an administrator \n" + "(2) Sign up \n" + "(3) Sign in as a client \n" + "Choice = "); run = int.Parse(Console.ReadLine()); if (run == 1) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Вход в базу администрации..."); Console.ForegroundColor = ConsoleColor.White; string log = "alifbank"; Console.Write("Введите Логин = "); log = Console.ReadLine(); string pas; Console.Write("Введите Пароль = "); pas = Console.ReadLine(); if (log == "alifbank" && pas == "2014") { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{new string('-', 5)}Admin Menu{new string('-', 5)}"); Console.ForegroundColor = ConsoleColor.White; Console.Write("1. Insert Client\n" + "2. Select all Clients\n" + "3. Select by Id \n" + "4. Update Client\n" + "5. Delete Client\n" + "5. Choice:"); int num = int.Parse(Console.ReadLine()); if (num == 1) { Console.Clear(); var customerModel = CreateCustomerClient(); var result = customerModel.CreateCustomer(); if (result > 0) { Console.WriteLine("Customer is added successfully"); } } if (num == 2) { Customer.ShowCustomers(); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } if (num == 3) { Customer.ShowCutromerIdmethod(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } if (num == 4) { try { Customer cust = new Customer(); Console.WriteLine("Enter Customer Id: "); cust.Id = int.Parse(Console.ReadLine()); Console.WriteLine("Enter new Fist Name for Customer: "); cust.FirstName = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Last Name: "); cust.LastName = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Middle Name: "); cust.MiddleName = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Marital Status: "); cust.MaritalStatus = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Citizenship: "); cust.Citizenship = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Documment Number: "); cust.DocumentNumber = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter new Login: "******"Enter new Password: "******"The Customer is successfully added!"); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine("ERROR While Updating Customer" + ex.Message); } } if (num == 5) { Customer.DeleteCustomer(); } } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Ошибка! Введите правильный пароль..."); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Press any key to return into the main menu..."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } } if (run == 2) { var customerModel = CreateCustomerClient(); var result = customerModel.CreateCustomer(); if (result > 0) { Console.WriteLine("Customer is added successfully"); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } if (run == 3) { Customer cust = new Customer(); bool x = true; SqlConnection connection = SqlClientModel.GetNewSqlConnection(); connection.Open(); while (x) { Console.Clear(); Console.WriteLine("Login:"******"Password:"******"select * from Customers where Login = @Login and Password = @Password"; SqlCommand command = new SqlCommand(cmdText, connection); command.Parameters.AddWithValue("Login", cust.Login); command.Parameters.AddWithValue("Password", cust.Password); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { //connection.Open(); x = false; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Successfully Enterder to your account"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to continue.."); Console.ReadKey(); if (connection.State == System.Data.ConnectionState.Open) { connection.Close(); } switch (CustomerMenu()) { case "1": { /* вызов метода CreateCredit() */ Console.Clear(); var CreditModel = CreateCredit(); var result = CreditModel.CreateCreditModel(); if (result > 0) { Console.WriteLine("Application is sucessfully accepted!"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press any key to continue ... "); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "2": { Credits.ShowCodeId(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } break; case "3": { Credits.MyLoanLoginShow(); } break; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Login or password was incorrect!"); Console.WriteLine("Press any key to get back to the main menu..."); Console.ReadKey(); //connection.Close(); ShowCustomerMenu(); Console.ForegroundColor = ConsoleColor.White; } Console.Clear(); } } connection.Close(); } } break; } } #region //switch (CustomerMenu()) //{ // case "1": // { // CreateCredit(); // Console.WriteLine("Press any key to continue..."); // Console.ReadLine(); // } // break; //} #endregion }