コード例 #1
0
        public List <Employee> GetEmployee(string name)
        {
            List <Employee> employeeList = new List <Employee>();
            int             flag         = 0;

            try
            {
                //Check if employees with specified name are present
                employeeList.AddRange(_list.FindAll(t => String.Equals(t.Name, name, StringComparison.OrdinalIgnoreCase)));
                if (employeeList.Count != 0)
                {
                    flag = 1;
                }
                if (flag == 0)
                {
                    throw new Exception();
                }
                return(employeeList);
            }
            catch
            {
                FaultExceptionContract faultcontract = new FaultExceptionContract();
                faultcontract.Message = "No record found for specified Name";
                throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("No record found for specified Name"));
            }
        }
コード例 #2
0
        public List <Employee> GetEmployeesByRemark(string remark)
        {
            List <Employee> remarkEmployeeList = new List <Employee>();
            int             flag = 0;

            try
            {
                //Check if employees with specified remark are present
                remarkEmployeeList.AddRange(_list.Where(t => t.Remarks.ContainsValue(remark)));
                if (remarkEmployeeList.Count != 0)
                {
                    flag = 1;
                }
                if (flag == 0)
                {
                    throw new Exception();
                }
                return(remarkEmployeeList);
            }
            catch
            {
                FaultExceptionContract faultcontract = new FaultExceptionContract();
                faultcontract.Message = "No record found for specified Remark";
                throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("No record found for specified Remark"));
            }
        }
コード例 #3
0
 public Employee GetEmployee(int id)
 {
     try
     {
         var employee = _list.Where(t => t.Id == id).FirstOrDefault();
         if (employee != null)
         {
             return(employee);
         }
         throw new Exception();
     }
     catch
     {
         FaultExceptionContract faultcontract = new FaultExceptionContract();
         faultcontract.Message = "No record found for specified Id";
         throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("No record found for specified Id"));
     }
 }
コード例 #4
0
 public List <Employee> GetEmployees()
 {
     try
     {
         //Check if employee list is empty
         if (_list.Count == 0)
         {
             throw new Exception();
         }
         return(_list);
     }
     catch
     {
         FaultExceptionContract faultcontract = new FaultExceptionContract();
         faultcontract.Message = "No employees added";
         throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("No employees added"));
     }
 }
コード例 #5
0
        public string AddRemarks(int id, string remarks)
        {
            try
            {
                //Check if employee with specified id is present
                var employee = _list.Where(t => t.Id == id).FirstOrDefault();
                if (employee != null)
                {
                    employee.Remarks.Add(System.DateTime.Now, remarks);
                    return("Remark added successfully");
                }

                throw new Exception();
            }
            catch
            {
                FaultExceptionContract faultcontract = new FaultExceptionContract();
                faultcontract.Message = "Record not found";
                throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("Record not found"));
            }
        }
コード例 #6
0
 public string CreateEmployee(int id, string name)
 {
     try
     {
         Employee e = new Employee();
         //Check if employee with specified id is already present
         var employee = _list.Where(t => t.Id == id).FirstOrDefault();
         if (employee != null)
         {
             throw new Exception();
         }
         e.Id   = id;
         e.Name = name;
         _list.Add(e);
         return("Record successfully added");
     }
     catch
     {
         FaultExceptionContract faultcontract = new FaultExceptionContract();
         faultcontract.Message = "Record Already Present with same ID";
         throw new FaultException <FaultExceptionContract>(faultcontract, new FaultReason("Record Already Present with same ID"));
     }
 }