Beispiel #1
0
        /// <summary>
        /// Fetches employee details
        /// </summary>
        public (List <Employee>, int, int, int) GetEmployeeDetails(int pageNumber)
        {
            List <Employee> employeeList = new List <Employee>();
            int             start        = 0;
            int             end          = 0;
            int             totalItems   = 0;

            try
            {
                var employeeDetails = WebAPI.GetEmployeesData(pageNumber);
                if (employeeDetails.Result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    string res = employeeDetails.Result.Content.ReadAsStringAsync().Result;
                    APISuccessResponseObjectWhenGet responseObj = JsonConvert.DeserializeObject <APISuccessResponseObjectWhenGet>(res);
                    employeeList = responseObj.data;
                    start        = ((pageNumber - 1) * responseObj.Meta.Pagination.Limit);
                    end          = (pageNumber * responseObj.Meta.Pagination.Limit);
                    totalItems   = responseObj.Meta.Pagination.Total;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(employeeList, start, end, totalItems);
        }
Beispiel #2
0
        /// <summary>
        /// Exports the entire employee data to CSV file
        /// in the same directory as the project
        /// </summary>
        public bool ExportToCSV()
        {
            bool isExportedSuccesfully = false;

            try
            {
                List <Employee> exportToCSVList = new List <Employee>();
                var             employeeDetails = WebAPI.GetEmployeesData();
                if (employeeDetails.Result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    string res = employeeDetails.Result.Content.ReadAsStringAsync().Result;

                    APISuccessResponseObjectWhenGet responseObj = JsonConvert.DeserializeObject <APISuccessResponseObjectWhenGet>(res);
                    exportToCSVList = responseObj.data;
                    for (int pageNumber = 2; pageNumber <= responseObj.Meta.Pagination.Pages; pageNumber++)
                    {
                        var paginatedEmployeeDetails = WebAPI.GetEmployeesData(pageNumber);
                        if (employeeDetails.Result.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            string paginatedResult = paginatedEmployeeDetails.Result.Content.ReadAsStringAsync().Result;
                            APISuccessResponseObjectWhenGet paginatedResponseObj = JsonConvert.DeserializeObject <APISuccessResponseObjectWhenGet>(paginatedResult);
                            exportToCSVList.AddRange(paginatedResponseObj.data);
                        }
                    }
                    DataTable EmployeeTable    = GetTable(exportToCSVList);
                    string    workingDirectory = Environment.CurrentDirectory;
                    string    startupPath      = Directory.GetParent(workingDirectory).Parent.Parent.FullName;
                    CSVUtlity.ToCSV(EmployeeTable, startupPath + "\\" + ConfigurationManager.AppSettings["ExportFileName"]);
                    isExportedSuccesfully = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(isExportedSuccesfully);
        }