public static FullTimeEmployee GetFullTimeEmployee() { FullTimeEmployee fte = new FullTimeEmployee { Id = 1, Name = "LAMGHARI", Gender = "M", Dateofb = Convert.ToDateTime("21/10/1988"), Type = EmployeeType.FullTimeEmployee, AnnualSalary = 32000 }; return fte; }
public Employee GetEmployeeDB(int Id) { ////try ////{ //if (Id == 0) // throw new FaultException("Id égal a zero",new FaultCode("IdIsEqualToZero")); LogDeb.LogException("EmployeeService", "GetEmployee", "GetEmployee Debut Ok"); //Employee employee = new Employee(); Employee employee = null; string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("spGetEmployee", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parameterId = new SqlParameter(); parameterId.ParameterName = "@Id"; parameterId.Value = Id; cmd.Parameters.Add(parameterId); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if ((EmployeeType)reader["EmployeeType"] == EmployeeType.FullTimeEmployee) { employee = new FullTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), AnnualSalary = Convert.ToInt32(reader["AnnualSalary"]), Type = EmployeeType.FullTimeEmployee }; } else { employee = new PartTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), HourlyPay = Convert.ToInt32(reader["HourlyPay"]), HoursWorked = Convert.ToInt32(reader["HoursWorked"]), Type = EmployeeType.PartTimeEmployee }; } } } LogDeb.LogException("EmployeeService", "GetEmployee", "Employee : " + employee.Id + " - " + employee.Name + " - " + employee.Type + " "); LogDeb.LogException("EmployeeService", "GetEmployee", "GetEmployee End Ok"); return employee; ////} ////catch (Exception ex) ////{ //// ZeroFault zeroException = new ZeroFault(); //// zeroException.Error = ex.Message; //// zeroException.Details = "Id cannot be ZERO"; //// throw new FaultException<ZeroFault>(zeroException); //// //return null; ////} //catch (FaultException faultException) //{ // LogDeb.LogException("EmployeeService", "GetEmployee", faultException.Message); // return null; //} }