I have created an employee class and EmployeeWebSerivce,
I need to create a controller class which exposes three HTTP endpoints: api/employees (GET)
Returning a list of all employees. Given a boolean parameter ‘hasOvertime’, the endpoint should be able to filter the list of Employees using the EmployeeService. E.g.: api/employees?hasOvertime=true.
api/employees (POST)
Taking an Employee object in the request body and storing it in the list of employees.
api/payments (GET)
Returning the sum of all monthly payments. Similar to the other GET method, you should be able to filter by overtime, given a boolean parameter.
I don't know how to call methods from EmployeeWebService class.
public class Employee
{
public String Name { get; set; }
public double HourlyWage { get; set; }
public double HoursPerMonth { get; set; }
public double GetMonthlyPay()
{
double overTimeHours= HoursPerMonth - 150;
double pay;
if(overTimeHours <= 0)
{
pay = HourlyWage * HoursPerMonth;
}
else
{
pay = (150 * HourlyWage) + (overTimeHours * HourlyWage * 1.5);
}
return pay;
}
EmployeeWebService
public class EmployeeWebService
{
private List<Employee> FilterEmployeeBasedOnOverTime(List<Employee> employee, bool hasOvertime = false)
{
return employee.Where(e => hasOvertime ? e.HoursPerMonth > 150 : e.HoursPerMonth <= 150).ToList();
}
private double GetTotalMonthlyExpense(List<Employee> employees)
{
return employees.Sum(e => e.GetMonthlyPay());
}