/// <summary> /// It Return All the Employee in the List /// If Employee Does not Exist in the list, then it will throw FaultException /// </summary> /// <returns>List</returns> public List <EmployeeManagement> GetAllEmployee() { EmployeeServiceFault fault = new EmployeeServiceFault(); if (_employeelist.Count() > 0) { return(_employeelist); } else { fault.FaultId = 100; fault.FaultMessage = "Employee Does not exits"; fault.FaultDetail = "Employee is Not Present in the List"; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } }
/// <summary> /// It Retrieve Employee Details by using Employee ID /// If Employee Does not Exist in the list, then it will throw FaultException /// </summary> /// <param name="id">Employee ID</param> /// <returns>Employee Object</returns> public EmployeeManagement GetEmployee(int id) { EmployeeServiceFault fault = new EmployeeServiceFault(); if (_employeelist.Any(e => e.EmployeeID == id)) { return(_employeelist.Find(e => e.EmployeeID.Equals(id))); } else { fault.FaultId = 100; fault.FaultMessage = "Employee Does not exits"; fault.FaultDetail = "Employee is Not Present in the List"; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } }
/// <summary> /// It Retrieve Employee Details of Employee Who has Comment/Remark /// If Employee Does not Exist in the list, then it will throw FaultException /// </summary> /// <returns></returns> List <EmployeeManagement> IEmployeeRetrieve.GetAllEmployeeWithComment() { EmployeeServiceFault fault = new EmployeeServiceFault(); var selectedEmployee = _employeelist.FindAll(e => e.Comment != null); if (selectedEmployee.Count() > 0) { return(_employeelist.FindAll(e => e.Comment != null)); } else { fault.FaultId = 100; fault.FaultMessage = "Employee Does not exits"; fault.FaultDetail = "Employee is Not Present in the List"; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } }
/// <summary> /// It Modify Comment of Already Existing Employee /// If Employee Does not Exist in the list, then it will throw FaultException /// </summary> /// <param name="id">Employee ID</param> /// <param name="comment">Employee Comment</param> /// <returns>Employee Object</returns> public EmployeeManagement ModifyComment(int id, string comment) { EmployeeServiceFault fault = new EmployeeServiceFault(); if (_employeelist.Any(e => e.EmployeeID == id)) { var empToModify = _employeelist.Find(e => e.EmployeeID.Equals(id)); empToModify.Comment = comment; return(empToModify); } else { fault.FaultId = 100; fault.FaultMessage = "Employee Does not exits"; fault.FaultDetail = "Employee is Not Present in the List"; throw new FaultException <EmployeeServiceFault>(fault); } }
/// <summary> /// It create Employee Object /// If Employee Already Exist in the list, then it will throw FaultException /// </summary> /// <param name="id">Employee Id</param> /// <param name="name">Employee Name</param> /// <param name="comment">Employee Comment</param> /// <returns>Employee Object</returns> public EmployeeManagement CreateEmployee(int id, string name, string comment) { EmployeeManagement employeeObj = new EmployeeManagement(); EmployeeServiceFault fault = new EmployeeServiceFault(); if (_employeelist.Any(e => e.EmployeeID == id)) { fault.FaultId = 101; fault.FaultMessage = "Employee Already Exists"; fault.FaultDetail = "Employee Already Present in the List"; throw new FaultException <EmployeeServiceFault>(fault, "Employee Already Exists"); } else { employeeObj.EmployeeID = id; employeeObj.EmployeeName = name; employeeObj.Comment = comment; employeeObj.TimeSubmitted = DateTime.Now; return(employeeObj); } }
private void EmployeeIDValidator(int empId) { //Regex employeeIdRegex = new Regex("^[0-9]+$"); if (empId < 0) { EmployeeServiceFault fault = new EmployeeServiceFault(); fault.FaultId = 105; fault.FaultMessage = "Employee ID Should be Postive"; fault.FaultDetail = "Employee ID Should be Postive ie ID Should be Greater than Zero "; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } //if (!employeeIdRegex.IsMatch(empId.ToString())) //{ // EmployeeServiceFault fault = new EmployeeServiceFault(); // fault.FaultId = 106; // fault.FaultMessage = "Employee ID Should Contains only Digits"; // fault.FaultDetail = "Employee ID Should Contains only Digits i.e [0-9]"; // throw new FaultException<EmployeeServiceFault>(fault, fault.FaultDetail); //} }
private void EmployeeNameValidator(string empName) { Regex employeeNameRegex = new Regex("^[a-zA-Z]+$"); if (empName.Equals(null)) { EmployeeServiceFault fault = new EmployeeServiceFault(); fault.FaultId = 107; fault.FaultMessage = "Employee Name Cannot be Null"; fault.FaultDetail = "Employee Name Cannot be Null , It should Contain Some Valid Name "; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } if (!employeeNameRegex.IsMatch(empName)) { EmployeeServiceFault fault = new EmployeeServiceFault(); fault.FaultId = 108; fault.FaultMessage = "Employee Name Should Contains Only Letters"; fault.FaultDetail = "Employee Name Should Contains Only Letters i.e [Aa-Zz]"; throw new FaultException <EmployeeServiceFault>(fault, fault.FaultDetail); } }