Exemple #1
0
        /// <summary>
        ///    Get All employees from API
        /// </summary>
        /// <returns></returns>
        public List <EmployeeDTO> GetEmployees()
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ConfigurationManager.AppSettings["ServiceUrl"]);

            request.Method = "GET";
            String             strEmployees = String.Empty;
            List <EmployeeDTO> lstemployees;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream       dataStream = response.GetResponseStream();
                StreamReader Sreader    = new StreamReader(dataStream);
                strEmployees = Sreader.ReadToEnd();
                lstemployees = JsonConvert.DeserializeObject <List <EmployeeDTO> >(strEmployees);

                foreach (var dato in lstemployees)
                {
                    if (dato.ContractTypeName.Equals("HourlySalaryEmployee"))
                    {
                        IFactoryEmployee factory = new HourFactory();
                        var objHourly            = factory.CreateEmployee();
                        objHourly.HourlySalary = dato.HourlySalary;
                        dato.AnualSalary       = objHourly.AnualSalary;
                    }
                    else
                    {
                        IFactoryEmployee factory = new MonthFactory();
                        var objMonth             = factory.CreateEmployee();
                        objMonth.MonthlySalary = dato.MonthlySalary;
                        dato.AnualSalary       = objMonth.AnualSalary;
                    }
                }

                Sreader.Close();
                dataStream.Close();
            }



            return(lstemployees);
        }
Exemple #2
0
        /// <summary>
        /// Get and employee by ID
        /// </summary>
        /// <param name="EmployeeID"></param>
        /// <returns></returns>
        public EmployeeDTO getEmployeebyID(int EmployeeID)
        {
            EmployeeDTO objEmployee = GetEmployees().Find(p => p.Id == EmployeeID);

            if (objEmployee != null)
            {
                if (objEmployee.ContractTypeName.Equals("HourlySalaryEmployee"))
                {
                    IFactoryEmployee factory = new HourFactory();
                    var objHourly            = factory.CreateEmployee();
                    objHourly.HourlySalary  = objEmployee.HourlySalary;
                    objEmployee.AnualSalary = objHourly.AnualSalary;
                }
                else
                {
                    IFactoryEmployee factory = new MonthFactory();
                    var objMonth             = factory.CreateEmployee();
                    objMonth.MonthlySalary  = objEmployee.MonthlySalary;
                    objEmployee.AnualSalary = objMonth.AnualSalary;
                }
            }

            return(objEmployee);
        }