/// <summary> /// Throws if the employee id is already present in the _employees list /// Creates a new employee with given id,name and remarks. /// if successful, adds the new employee in the _employee list. /// </summary> /// <param name="name">string</param> /// <param name="remarks">string</param> /// <returns>Employee</returns> public Employee CreateEmployee(string name, string remarks) { _idGenerator++; //Check if the employee id is already present in the list,is yes then throw. if (_employees.Any(emp1 => emp1.EmpId == _idGenerator)) { var fault = new EmployeeAlreadyExistsFault { FaultId = 101, Message = "Employee Already Exists.Please try again" }; throw new FaultException <EmployeeAlreadyExistsFault> (fault, "Employee Already Exists."); } //Else create a new employee and add it in the list var emp = new Employee { EmpId = _idGenerator, EmpName = name }; var remark = new Remarks { Text = remarks, RemarkTimestamp = DateTime.Now }; emp.Remark = remark; _employees.Add(emp); return(emp); }
public Employee CreateEmployee(int id, string name) { if (_employees.Any(empolyee => empolyee.Id == id)) { EmployeeAlreadyExistsFault fault = new EmployeeAlreadyExistsFault { FaultId = 101, Message = "Employee with Id " + id + " already exists" }; throw new FaultException <EmployeeAlreadyExistsFault> (fault, "Employee with Id " + id + " already exists"); } Employee employee = GetEmployeeObject(id, name); _employees.Add(employee); return(employee); }