// UC 3 public double UpdateEmployeePayroll(PayrollUpdateModel payrollModel) { string connectionString = @"data source=(localDB)\testDB; database=payroll_service;"; SqlConnection connection = new SqlConnection(connectionString); double payroll = 0; try { using (connection) { EmployeeModel employeeModel = new EmployeeModel(); SqlCommand command = new SqlCommand("spUpdateEmployeePayroll", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Payroll_ID", payrollModel.Payroll_ID); command.Parameters.AddWithValue("@BasicPay", payrollModel.BasicPay); command.Parameters.AddWithValue("@Deductions", payrollModel.Deductions); command.Parameters.AddWithValue("@IncomeTax", payrollModel.IncomeTax); command.Parameters.AddWithValue("@Emp_ID", payrollModel.Emp_ID); connection.Open(); SqlDataReader dr = command.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { employeeModel.Emp_ID = Convert.ToInt32(dr["Emp_ID"]); employeeModel.Name = dr["Emp_Name"].ToString(); employeeModel.BasicPay = Convert.ToDouble(dr["BasicPay"]); Console.WriteLine("{0}, {1}", employeeModel.Name, employeeModel.BasicPay); payroll = employeeModel.BasicPay; } } else { Console.WriteLine("No data found"); } dr.Close(); connection.Close(); return(payroll); } } catch (Exception e) { throw new Exception(e.Message); } finally { connection.Close(); } }
static void Main(string[] args) { Console.WriteLine("Welcome to Employee Payroll Problem -Section3!"); EmployeeRepo employeeRepo = new EmployeeRepo(); EmployeeModel employee = new EmployeeModel(); PayrollUpdateModel payroll = new PayrollUpdateModel(); employee.Name = "Lawrene"; employee.PhoneNumber = "8885568964"; employee.Address = "LA"; employee.Gender = 'F'; payroll.BasicPay = 5000.00; payroll.Deductions = 500; payroll.IncomeTax = 200; //employeeRepo.AddEmployeeToPayroll(payroll, employee); //employeeRepo.GetEmployee(); }