/// <summary> /// Returns the list of all Employees. /// Throws fault if the list is empty. /// </summary> /// <returns>_employees</returns> public List <Employee> GetAllEmployeeList() { if (_employees.Count > 0) { return(_employees); } var fault = new EmployeeDoesNotExists { FaultId = 105, Message = "Employee List is Empty.Please add new employees and then try again." }; throw new FaultException <EmployeeDoesNotExists>(fault, "Employee List in Empty"); }
/// <summary> /// Adds remarks for an employee for a given employee Name. /// If remark successfully added for existing employee,Writes to the output(debug). /// Throws faultException if employee id is not present int the _employee list. /// </summary> /// <param name="name">string</param> /// <param name="remarks">string</param> /// <returns>void</returns> public void AddRemarks(string name, string remarks) { if (_employees.Any(emp => emp.EmpName == name)) { int index = _employees.IndexOf(_employees.First(emp => emp.EmpName == name)); _employees[index].Remark.Text = remarks; } else { var fault = new EmployeeDoesNotExists { FaultId = 102, Message = "Employee Does not exits" }; throw new FaultException <EmployeeDoesNotExists>(fault, "Employee Does not exists."); } }
/// <summary> /// Returns Employee Details for a requested Employee Name /// Throws if the requested Emplyee Name does not exist in the list /// </summary> /// <param name="name">string</param> /// <returns>Employee</returns> public Employee GetEmployeeDetails(string name) { if (_employees.Any(emp => emp.EmpName == name)) { var selectedEmployee = _employees.First(emp => emp.EmpName == name); return(selectedEmployee); } else { var fault = new EmployeeDoesNotExists { FaultId = 103, Message = "Employee Name you searched does not Exist.Please try again" }; throw new FaultException <EmployeeDoesNotExists>(fault, "Employee Name you searched does not Exist"); } }
/// <summary> /// Returns the employee object for a given employee ID. /// Throws is the requested employee ID is not present in the _employee list. /// </summary> /// <param name="id">int</param> /// <returns>Employee</returns> public Employee GetEmployeeDetails(int id) { if (_employees.Any(emp => emp.EmpId == id)) { Employee selectedEmployee = _employees.Where(emp => emp.EmpId == id).First(); return(selectedEmployee); } else { var fault = new EmployeeDoesNotExists { FaultId = 113, Message = "Employee Name you searched does not Exist.Please try again" }; throw new FaultException <EmployeeDoesNotExists>(fault, "Employee Id you searched does not Exist"); } }
public void DeleteEmployee(string name) { if (_employees.Any(emp => emp.EmpName == name)) { int index = _employees.IndexOf(_employees.First(emp => emp.EmpName == name)); _employees.Remove(_employees.First(emp => emp.EmpName == name)); Debug.WriteLine("Employee removed"); } else { var fault = new EmployeeDoesNotExists { FaultId = 104, Message = "Employee id you want to delete does not exists.Please try again." }; throw new FaultException <EmployeeDoesNotExists>(fault, "Employee id you want to delete does not exists"); } }