public void EmployeeUpdateById_Return_OkResult() { EmployeesTableDetails employee = new EmployeesTableDetails(); var result = controller.UpdateEmployeeRecord(employee); Assert.IsType <OkObjectResult>(result); }
//Method to Update record public EmployeesTableDetails UpdateEmployeeRecord(EmployeesTableDetails employees) { try { var result = employeeRL.UpdateEmployeeRecord(employees); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
//Method to add employee's records public EmployeesTableDetails AddEmployeesRecords(EmployeesTableDetails employee) { try { var result = employeeRL.AddEmployeesRecords(employee); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
public IActionResult UpdateEmployeeRecord(EmployeesTableDetails employees) { try { var result = employeeBL.UpdateEmployeeRecord(employees); return(Ok(new { result })); } catch (Exception) { return(BadRequest()); } }
//Method for Getting records of all the employees from the table public List <EmployeesTableDetails> GetEmployeesRecords() { //Stored Procedure initialized string Procedure = "ViewAllrecords"; // Creat list of recoeds of all the employee List <EmployeesTableDetails> employees = new List <EmployeesTableDetails>(); try { using (SqlConnection Connection = new SqlConnection(this.ConnectionString)) { //Calling stored procedure SqlCommand sqlCommand = new SqlCommand(Procedure, Connection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; //Connection open Connection.Open(); //Read the data by using sql command SqlDataReader dataReader = sqlCommand.ExecuteReader(); while (dataReader.Read()) { EmployeesTableDetails employeesTable = new EmployeesTableDetails(); employeesTable.UserId = Convert.ToInt32(dataReader["UserId"].ToString()); employeesTable.FirstName = dataReader["FirstName"].ToString(); employeesTable.LastName = dataReader["LastName"].ToString(); employeesTable.Gender = dataReader["Gender"].ToString(); employeesTable.Email = dataReader["Email"].ToString(); employeesTable.Address = dataReader["Address"].ToString(); employeesTable.Designation = dataReader["Designation"].ToString(); employeesTable.Salary = Convert.ToDouble(dataReader["Salary"].ToString()); employeesTable.MobileNumber = dataReader["MobileNumber"].ToString(); employeesTable.Password = dataReader["Password"].ToString(); employees.Add(employeesTable); } //Connection close Connection.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(employees); }
//Method to add an Employee's data in the table public EmployeesTableDetails AddEmployeesRecords(EmployeesTableDetails employees) { //Stored Procedure initialized string Procedure = "InsertDetails"; try { using (SqlConnection Connection = new SqlConnection(this.ConnectionString)) { //Calling the stored procedure SqlCommand sqlCommand = new SqlCommand(Procedure, Connection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@FirstName", employees.FirstName); sqlCommand.Parameters.AddWithValue("@LastName", employees.LastName); sqlCommand.Parameters.AddWithValue("@Gender", employees.Gender); sqlCommand.Parameters.AddWithValue("@Email", employees.Email); sqlCommand.Parameters.AddWithValue("@Address", employees.Address); sqlCommand.Parameters.AddWithValue("@Designation", employees.Designation); sqlCommand.Parameters.AddWithValue("@Salary", employees.Salary); sqlCommand.Parameters.AddWithValue("@MobileNumber", employees.MobileNumber); sqlCommand.Parameters.AddWithValue("@Password", employees.Password); //connection open Connection.Open(); //Execute query sqlCommand.ExecuteNonQuery(); //connection close Connection.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(employees); }
public void AddEmployee_ReturnsOkResult() { // Arrange var employee = new EmployeesTableDetails() { FirstName = "", LastName = "", Gender = "", Email = "", Address = "", Designation = "", Salary = 0, MobileNumber = "", Password = "" }; // Act var OkResponse = controller.AddEmployeesRecords(employee); // Assert Assert.IsType <OkObjectResult>(OkResponse); }
//Method to get empoyee data by its Id public EmployeesTableDetails GetEmployeeRecordById(int UserId) { //Stored procedure declared string Procedure = "ViewRecordsById"; //Create instanve of Model class EmployeesTableDetails employee = new EmployeesTableDetails(); try { using (SqlConnection Connection = new SqlConnection(this.ConnectionString)) { SqlCommand sqlCommand = new SqlCommand(Procedure, Connection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@UserId", UserId); Connection.Open(); SqlDataReader dataReader = sqlCommand.ExecuteReader(); while (dataReader.Read()) { employee.UserId = Convert.ToInt32(dataReader["UserId"].ToString()); employee.FirstName = dataReader["FirstName"].ToString(); employee.LastName = dataReader["LastName"].ToString(); employee.Gender = dataReader["Gender"].ToString(); employee.Email = dataReader["Email"].ToString(); employee.Address = dataReader["Address"].ToString(); employee.Designation = dataReader["Designation"].ToString(); employee.Salary = Convert.ToDouble(dataReader["Salary"].ToString()); employee.MobileNumber = dataReader["MobileNumber"].ToString(); employee.Password = dataReader["Password"].ToString(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(employee); }