コード例 #1
0
        public int UpdateEmployeeSalary(SalaryUpdateModel model)
        {
            SqlConnection SalaryConnection = ConnectionSetup();
            int           salary           = 0;

            try
            {
                using (SalaryConnection)
                {
                    SalaryDetailModel displayModel = new SalaryDetailModel();
                    //define the SqlCommand object
                    SqlCommand command = new SqlCommand("spUpdateEmployeeSalary", SalaryConnection);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@id", model.SalaryId);
                    command.Parameters.AddWithValue("@month", model.Month);
                    command.Parameters.AddWithValue("@salary", model.EmployeeSalary);
                    command.Parameters.AddWithValue("@EmpId", model.EmployeeId);
                    SalaryConnection.Open();

                    SqlDataReader dr = command.ExecuteReader();

                    //check if there are records
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            displayModel.EmployeeId     = Convert.ToInt32(dr["EmpId"]);
                            displayModel.EmployeeName   = dr["ENAME"].ToString();
                            displayModel.JobDiscription = dr["JOB"].ToString();
                            displayModel.EmployeeSalary = Convert.ToInt32(dr["EMPSAL"]);
                            displayModel.Month          = dr["SAL_MONTH"].ToString();
                            displayModel.SalaryId       = Convert.ToInt32(dr["SALARYId"]);

                            //display retrieved record
                            Console.WriteLine("{0},{1},{2}", displayModel.EmployeeName, displayModel.EmployeeSalary, displayModel.Month);
                            Console.WriteLine("\n");
                            salary = displayModel.EmployeeSalary;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data found.");
                    }
                    //close data reader
                    dr.Close();

                    SalaryConnection.Close();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
            return(salary);
        }
コード例 #2
0
        /// <summary>
        /// Display all emp Salary
        /// </summary>
        public void DisplayAllSalaryDetail()
        {
            SqlConnection SalaryConnection = ConnectionSetup();

            try
            {
                using (SalaryConnection)
                {
                    SalaryDetailModel displayModel = new SalaryDetailModel();
                    //define the SqlCommand object
                    SqlCommand cmd = new SqlCommand("spGetAllSalaryDetail", SalaryConnection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SalaryConnection.Open();

                    SqlDataReader dr = cmd.ExecuteReader();

                    //check if there are records
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            displayModel.EmployeeId     = Convert.ToInt32(dr["EmpId"]);
                            displayModel.EmployeeName   = dr["ENAME"].ToString();
                            displayModel.JobDiscription = dr["JOB"].ToString();
                            displayModel.EmployeeSalary = Convert.ToInt32(dr["EMPSAL"]);
                            displayModel.Month          = dr["SAL_MONTH"].ToString();
                            displayModel.SalaryId       = Convert.ToInt32(dr["SALARYId"]);

                            //display retrieved record
                            Console.WriteLine("{0},{1},{2}", displayModel.EmployeeName, displayModel.EmployeeSalary, displayModel.Month);
                            Console.WriteLine("\n");
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data found.");
                    }
                    //close data reader
                    dr.Close();

                    SalaryConnection.Close();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
        }
コード例 #3
0
        public void UC3_CompareUpdatedSalary()
        {
            SalaryDetailModel model = new SalaryDetailModel()
            {
                EmployeeId = 1,
                SalaryId   = 1021,
                Salary     = 3000000,
                Month      = "Jan",
            };
            EmployeeRepo repo   = new EmployeeRepo();
            int          actual = repo.UpdateEmployee(model);

            Assert.AreEqual(model.Salary, actual);
        }
コード例 #4
0
        public int UpdateEmployeeSalary(SalaryUpdateModel salaryUpdateModel)
        {
            SqlConnection SalaryConnection = ConnectionSetup();
            int           salary           = 0;

            try
            {
                using (SalaryConnection)
                {
                    SalaryDetailModel displayModel = new SalaryDetailModel();
                    SqlCommand        command      = new SqlCommand("spUpdateEmployeeSalary", SalaryConnection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@id", salaryUpdateModel.SalaryId);
                    command.Parameters.AddWithValue("@month", salaryUpdateModel.Month);
                    command.Parameters.AddWithValue("@salary", salaryUpdateModel.EmployeeSalary);
                    command.Parameters.AddWithValue("@EmpId", salaryUpdateModel.EmployeeId);
                    SalaryConnection.Open();
                    SqlDataReader dr = command.ExecuteReader();
                    //salary = salaryUpdateModel.EmployeeSalary;
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            displayModel.EmployeeId     = Convert.ToInt32(dr["EmpId"]);
                            displayModel.EmployeeName   = dr["ENAME"].ToString();
                            displayModel.JobDescription = dr["jOB"].ToString();
                            displayModel.EmployeeSalary = Convert.ToInt32(dr["EMPSAL"]);
                            displayModel.Month          = dr["SAL_MONTH"].ToString();
                            displayModel.SalaryId       = Convert.ToInt32(dr["SALARYId"]);
                            Console.WriteLine(displayModel.EmployeeName + " " + displayModel.EmployeeSalary + " " + displayModel.Month);
                            Console.WriteLine("\n");
                            salary = displayModel.EmployeeSalary;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data found.");
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
            return(salary);
        }
コード例 #5
0
        public void GivenEmployeeName_AbleToRetrieveSalaryDetails()
        {
            Salary            salary   = new Salary();
            SalaryDetailModel expected = new SalaryDetailModel()
            {
                EmployeeId     = 2,
                EmployeeSalary = 1300,
                EmployeeName   = "Vijay",
                Deductions     = 500,
                TaxablePay     = 0,
                NetPay         = 18500,
                tax            = 500
            };

            SalaryDetailModel actual = salary.getEmployeeObject("Vijay");

            Assert.IsTrue(expected.Equals(actual));
        }