/// <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 void AddRemarks(int employeeId, string remarkText) { if (IsEmployeeIdExists(employeeId)) { Remarks remark = new Remarks(); remark.DateTime = DateTime.UtcNow; remark.EmployeeId = employeeId; remark.Remark = remarkText; _remarksList.Add(remark); } else { throw new FaultException <EmployeeServiceException>(CreateException(101, "Employee With given id does not exists " + employeeId), "Exception Occured"); } }
public Employee() { Remarks.Add(System.DateTime.Now, "No Remarks yet"); }