using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using TTSW.EF; using TTSW.Utils; using TTSW.Constant; using TTSW.Common; using TodoAPI2.Models; using System.IO; using System.Web; using System.Net; using TTSW.Configure; using Microsoft.Extensions.Options; using System.Data; using Npgsql; namespace TodoAPI2.Models { public class external_employeeService : Iexternal_employeeService { private IMyDatabase db; public external_employeeService(IMyDatabase mydb) { db = mydb; } public int? GetLeader(int? emp_id) { var sql = @" SELECT ha.employee_id as emp_id, CONCAT(hta.title_name,ha.firstname,' ',ha.lastname) as emp_name, ha.chief_id, CONCAT(htb.title_name,hb.firstname,' ',hb.lastname) as chief_name FROM public.hrm_employees as ha left join public.hrm_employees as hb on hb.employee_id = ha.chief_id left join public.hrm_title_masters as hta on hta.id = ha.prefix_card_name left join public.hrm_title_masters as htb on hb.prefix_card_name = htb.id where ha.employee_id = @emp_id and ha.workingstatus = 'สถานะปฏิบัติงาน'; "; var para = db.GetParameterListNpgsql(); var ix = new NpgsqlParameter("emp_id", DbType.Int32); ix.Value = emp_id; para.Add(ix); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); if (dt.Rows.Count == 1) { if (dt.Rows[0]["chief_id"] == DBNull.Value) { return null; } else { return Convert.ToInt32(dt.Rows[0]["chief_id"]); } } return null; } public List GetListByemployee_type(int? employee_type, int? position_type) { return GetAllEmployee(); } public List GetAllEmployee() { var sql = string.Format(@" select he.employee_id as id, mpn.position_number,he.employee_no,he.position_no, CONCAT(htm.title_name,' ',he.firstname,' ',he.lastname) as fullname,opd.position_name, CONCAT(he.firstname,he.lastname) as halfname, orgdata.id as department_id,orgdata.department_name,orgdata.department_code,he.salary, he.employee_type_id, het.employee_type_name,opd.position_id as position_id, u.email as user_email, u.id as user_id,hpl.position_level_name, he.profile_picture, he.position_level_id, he.position_type_id, hpl.position_level_id as hpl_position_level_id, hpt.position_type_id as hpt_position_type_id, he.position_allowance, he.other_money, hpt.position_type_name,he.packing_date,he.cost_of_living, (CASE WHEN (SELECT hrm_work_rec.id FROM hrm_working_records as hrm_work_rec WHERE hrm_work_rec.employee_id = he.employee_id AND hrm_work_rec.start_date <= now() AND hrm_work_rec.end_date >= now() AND hrm_work_rec.deleted_at IS null LIMIT 1) IS NOT null THEN 'ช่วยปฎิบัติหน้าที่' ELSE null END) as remark_hrm_work_record, org_type_depart.department_degree_id, he.timerecorder_id, (select count(*) from hrm_resigns where hrm_resigns.employee_id = he.employee_id) as count_resigns from public.hrm_employees as he left join public.hrm_position_types as hpt on he.position_type_id=hpt.id left join public.hrm_position_levels as hpl on he.position_level_id = hpl.id left join public.mpp_position_numbers as mpn on he.position_no = mpn.id left join public.org_position_datas as opd on opd.position_id = mpn.position_id left join public.hrm_title_masters as htm on htm.id = he.prefix_card_name left join public.{0}DepartmentData{0} as orgdata on orgdata.id = he.department_id left join public.hrm_employee_types as het on het.id = he.employee_type_id left join public.users as u on u.employee_id = he.employee_id left join public.org_type_departments as org_type_depart on orgdata.department_type_id = org_type_depart.id left join public.org_type_department_colors as org_depart_color on org_type_depart.department_degree_id = org_depart_color.id left join (select orgdata.id,orgdata2.id as id2, case when orgdata2.department_name is not null then concat(orgdata2.department_name,' - ',orgdata.department_name) else orgdata.department_name end as full_dep, orgdata.department_name, orgdata.department_code,detail.parent_department_id, case when org_type_depart.department_degree_id = 1 then orgdata.department_code::int*1000 when detail.parent_department_id is not null and detail.parent_department_id>0 then orgdata2.department_code::int*1000+orgdata.department_code::int else orgdata.department_code::int*100000 end as sort_order,org_type_depart.department_degree_id from public.{0}DepartmentData{0} orgdata left join org_organization_chart_details detail on orgdata.id = detail.department_id left join public.{0}DepartmentData{0} orgdata2 on orgdata2.id = detail.parent_department_id left join public.org_type_departments as org_type_depart on orgdata.department_type_id = org_type_depart.id left join public.org_type_department_colors as org_depart_color on org_type_depart.department_degree_id = org_depart_color.id where orgdata.department_name is not null order by case when org_type_depart.department_degree_id = 1 then orgdata.department_code::int*1000 when detail.parent_department_id is not null and detail.parent_department_id>0 then orgdata2.department_code::int*1000+orgdata.department_code::int else orgdata.department_code::int*100000 end) as sorting_dep on sorting_dep.id = he.department_id where he.deleted_at is null and hpt.deleted_at is null and hpl.deleted_at is null and mpn.deleted_at is null and opd.deleted_at is null and htm.deleted_at is null and orgdata.deleted_at is null and het.deleted_at is null and u.deleted_at is null and org_type_depart.deleted_at is null and org_depart_color.deleted_at is null order by sorting_dep.sort_order, hpt.position_type_id, hpl.position_level_id, employee_no desc; ", '"'.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new external_employeeViewModel(); i.id = Convert.ToInt32(dr["id"]); i.profile_picture = dr["profile_picture"].ToString(); i.position_number = dr["position_number"].ToString(); i.position_name = dr["position_name"].ToString(); i.fullname = dr["fullname"].ToString(); i.halfname = dr["halfname"].ToString(); if (dr["employee_type_id"] != DBNull.Value) { i.employee_type_id = Convert.ToInt32(dr["employee_type_id"]); i.employee_type_name = dr["employee_type_name"].ToString(); } if (dr["position_type_id"] != DBNull.Value) { i.position_type_id = Convert.ToInt32(dr["position_type_id"]); i.position_type_name = dr["position_type_name"].ToString(); i.hpt_position_type_id = Convert.ToInt32(dr["hpt_position_type_id"]); } if (dr["position_id"] != DBNull.Value) { i.position_id = Convert.ToInt32(dr["position_id"]); } if (dr["user_id"] != DBNull.Value) { i.user_email = dr["user_email"].ToString(); i.user_id = Convert.ToInt32(dr["user_id"]); } if (dr["department_id"] != DBNull.Value) { i.department_id = Convert.ToInt32(dr["department_id"]); i.department_name = dr["department_name"].ToString(); i.department_code = dr["department_code"].ToString(); } if (dr["employee_no"] != DBNull.Value) { i.employee_no = dr["employee_no"].ToString(); } if (dr["position_level_id"] != DBNull.Value) { i.position_level_id = Convert.ToInt32(dr["position_level_id"]); i.position_level_text = dr["position_level_name"].ToString(); i.hpl_position_level_id = Convert.ToInt32(dr["hpl_position_level_id"]); } i.salary = 0; if (dr["salary"] != DBNull.Value) { i.salary = Convert.ToDecimal(dr["salary"]); } i.cost_of_living = 0; if (dr["cost_of_living"] != DBNull.Value) { i.cost_of_living = Convert.ToDecimal(dr["cost_of_living"]); } if (dr["position_allowance"] != DBNull.Value) { i.position_allowance = Convert.ToDecimal(dr["position_allowance"]); } if (dr["other_money"] != DBNull.Value) { i.other_money = Convert.ToDecimal(dr["other_money"]); } if (dr["packing_date"] != DBNull.Value) { i.packing_date = Convert.ToDateTime(dr["packing_date"]); } if (dr["department_degree_id"] != DBNull.Value) { i.department_degree_id = Convert.ToInt32(dr["department_degree_id"]); } if (dr["remark_hrm_work_record"] != DBNull.Value) { i.remark_hrm_work_record = dr["remark_hrm_work_record"].ToString(); } if (dr["timerecorder_id"] != DBNull.Value) { i.timerecorder_id = dr["timerecorder_id"].ToString(); } else { i.timerecorder_id = ""; } if (dr["count_resigns"] != DBNull.Value) { i.count_resigns = Convert.ToInt32(dr["count_resigns"]); } else { i.count_resigns = 0; } result.Add(i); } return result; } public external_employeeViewModel GetEmployeeForLogin(int? user_id) { var sql = @" select he.employee_id as id, mpn.position_number, opd.position_name, CONCAT(htm.title_name,' ',he.firstname,' ',he.lastname) as fullname, u.email as user_email, u.id as user_id,u.name as fullname2 from public.hrm_employees as he left join public.mpp_position_numbers as mpn on he.position_no = mpn.id left join public.org_position_datas as opd on opd.position_id = mpn.position_id left join public.hrm_title_masters as htm on htm.id = he.prefix_card_name left join public.users as u on u.employee_id = he.employee_id where he.workingstatus = 'สถานะปฏิบัติงาน' and he.deleted_at is null and mpn.deleted_at is null and opd.deleted_at is null --and htm.deleted_at is null and u.id=@user_id; "; var para = db.GetParameterListNpgsql(); var ix = new NpgsqlParameter("user_id", DbType.Int32); ix.Value = user_id; para.Add(ix); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new external_employeeViewModel(); i.id = Convert.ToInt32(dr["id"]); i.position_number = dr["position_number"].ToString(); i.position_name = dr["position_name"].ToString(); i.fullname = dr["fullname2"].ToString(); i.employee_type_id = null; i.position_type_id = null; if (dr["user_id"] != DBNull.Value) { i.user_email = dr["user_email"].ToString(); i.user_id = Convert.ToInt32(dr["user_id"]); } result.Add(i); } if (result.Count == 1) { return result[0]; } else { return null; } } public employee_leaveViewModel GetLeaveOfEmployee(int employee_id, DateTime? start_date, DateTime? end_date) { var sql = string.Format(@" select {0}b{0}.{0}employee_id{0}, ( SELECT SUM(tad_general.total_dayoff) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 2 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as sum_day_sick_leave, ( SELECT COUNT(tad_general.*) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 2 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as count_sick_leave, ( SELECT SUM(tad_general.total_dayoff) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 4 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as sum_day_personal_leave, ( SELECT COUNT(tad_general.*) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 4 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as count_personal_leave, ( SELECT SUM(tad_general.total_dayoff) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 1 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as sum_day_vacation_leave, ( SELECT COUNT(tad_general.*) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id = 1 AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as count_vacation_leave, ( SELECT COUNT(DISTINCT tad_stop.date) FROM tad_stop_workings as tad_stop WHERE tad_stop.deleted_at is null AND tad_stop.employee_id = b.employee_id AND tad_stop.date BETWEEN @start_date AND @end_date ) as count_stop_working, ( SELECT COUNT(prs_time_result.id) FROM tad_processing_time_results as prs_time_result LEFT JOIN tad_processing_times as prs_time ON prs_time_result.processing_time_id = prs_time.id WHERE prs_time_result.deleted_at is null AND prs_time.deleted_at is null AND prs_time_result.employee_id = b.employee_id AND prs_time_result.time_in is not null AND prs_time_result.time_out is not null AND prs_time_result.late is not null AND prs_time_result.date BETWEEN @start_date AND @end_date ) as count_late_tad_processing_time_results, ( SELECT COUNT(prs_time_result.id) FROM tad_processing_time_results as prs_time_result LEFT JOIN tad_processing_times as prs_time ON prs_time_result.processing_time_id = prs_time.id WHERE prs_time_result.deleted_at is null AND prs_time.deleted_at is null AND prs_time_result.employee_id = b.employee_id AND prs_time_result.time_in is null AND prs_time_result.time_out is null AND prs_time_result.record_type = 'Absence' AND prs_time_result.date BETWEEN @start_date AND @end_date ) as count_absence_tad_processing_time_results, ( SELECT SUM(tad_general.total_dayoff) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id in (2,4) AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as sum_day_sick_personal_leave, ( SELECT COUNT(tad_general.*) FROM tad_general_leaves as tad_general LEFT JOIN tad_leave_types as leave_type ON tad_general.leave_type_id = CAST(leave_type.id as varchar) WHERE tad_general.deleted_at is null AND leave_type.deleted_at is null AND leave_type.id in (2,4) AND tad_general.employee_id = b.employee_id AND tad_general.status = '3' AND tad_general.start_date >= @start_date AND tad_general.end_date <= @end_date ) as count_sick_personal_leave from {0}tad_table_workings{0} as {0}a{0} left join {0}hrm_employees{0} as {0}b{0} on {0}a{0}.{0}employee_id{0} = {0}b{0}.{0}employee_id{0} left join {0}tad_workshifts{0} as {0}c{0} on {0}a{0}.{0}workshift_id{0} = {0}c{0}.{0}id{0} where {0}a{0}.{0}deleted_at{0} is null and {0}b{0}.{0}deleted_at{0} is null and {0}c{0}.{0}deleted_at{0} is null and {0}b{0}.{0}employee_id{0} = @employee_id ", '"'.ToString()); var para = db.GetParameterListNpgsql(); var p_employee_id = new NpgsqlParameter("employee_id", DbType.Int32); p_employee_id.Value = employee_id; para.Add(p_employee_id); var p_start_date = new NpgsqlParameter("start_date", DbType.Date); p_start_date.Value = start_date; para.Add(p_start_date); var p_end_date = new NpgsqlParameter("end_date", DbType.Date); p_end_date.Value = end_date; para.Add(p_end_date); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var dr = dt.Rows[0]; var i = new employee_leaveViewModel(); i.sum_day_sick_leave = 0; i.count_sick_leave = 0; i.sum_day_personal_leave = 0; i.count_personal_leave = 0; i.sum_day_vacation_leave = 0; i.count_vacation_leave = 0; i.count_stop_working = 0; i.count_late_tad_processing_time_results = 0; i.count_absence_tad_processing_time_results = 0; i.sum_day_sick_personal_leave = 0; i.count_sick_personal_leave = 0; if (dr["sum_day_sick_leave"] != DBNull.Value) { i.sum_day_sick_leave = Convert.ToDecimal(dr["sum_day_sick_leave"]); } if (dr["count_sick_leave"] != DBNull.Value) { i.count_sick_leave = Convert.ToDecimal(dr["count_sick_leave"]); } if (dr["sum_day_personal_leave"] != DBNull.Value) { i.sum_day_personal_leave = Convert.ToDecimal(dr["sum_day_personal_leave"]); } if (dr["count_personal_leave"] != DBNull.Value) { i.count_personal_leave = Convert.ToDecimal(dr["count_personal_leave"]); } if (dr["sum_day_vacation_leave"] != DBNull.Value) { i.sum_day_vacation_leave = Convert.ToDecimal(dr["sum_day_vacation_leave"]); } if (dr["count_vacation_leave"] != DBNull.Value) { i.count_vacation_leave = Convert.ToDecimal(dr["count_vacation_leave"]); } if (dr["count_stop_working"] != DBNull.Value) { i.count_stop_working = Convert.ToDecimal(dr["count_stop_working"]); } if (dr["count_late_tad_processing_time_results"] != DBNull.Value) { i.count_late_tad_processing_time_results = Convert.ToDecimal(dr["count_late_tad_processing_time_results"]); } if (dr["count_absence_tad_processing_time_results"] != DBNull.Value) { i.count_absence_tad_processing_time_results = Convert.ToDecimal(dr["count_absence_tad_processing_time_results"]); } if (dr["sum_day_sick_personal_leave"] != DBNull.Value) { i.sum_day_sick_personal_leave = Convert.ToDecimal(dr["sum_day_sick_personal_leave"]); } if (dr["count_sick_personal_leave"] != DBNull.Value) { i.count_sick_personal_leave = Convert.ToDecimal(dr["count_sick_personal_leave"]); } return i; } public List GetAllMenu() { var sql = string.Format(@" select cself.icon,cself.id, case when cself.parent_id is null and pmenu.parent_id is null then cself.sort when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort else pmenu2.sort end as psort, case when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id else 100000*pmenu.parent_id+1000*pmenu.id+cself.id end as pid,cself.display_name from core_menu as cself left join core_menu as pmenu on cself.parent_id=pmenu.id left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id where cself.id in ( select model_id from model_has_roles where model_type='App\Models\Menu' and role_id in (select id from roles where id in ( select role_id from model_has_roles where model_type='App\Models\User' and model_id in (select id from users) order by model_id )) ) order by case when cself.parent_id is null and pmenu.parent_id is null then cself.sort when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort else pmenu2.sort end, case when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id else 100000*pmenu.parent_id+1000*pmenu.id+cself.id end ", '"'.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new external_menu(); i.icon = dr["icon"].ToString(); i.id = Convert.ToInt32(dr["id"]); i.psort = Convert.ToInt32(dr["psort"]); i.pid = Convert.ToInt32(dr["pid"]); i.display_name = dr["display_name"].ToString(); result.Add(i); } return result; } public List GetMenuByUser(int? userid) { var sql = string.Format(@" select cself.icon,cself.id, case when cself.parent_id is null and pmenu.parent_id is null then cself.sort when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort else pmenu2.sort end as psort, case when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id else 100000*pmenu.parent_id+1000*pmenu.id+cself.id end as pid,cself.display_name from core_menu as cself left join core_menu as pmenu on cself.parent_id=pmenu.id left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id where cself.id in ( select model_id from model_has_roles where model_type='App\Models\Menu' and role_id in (select id from roles where id in ( select role_id from model_has_roles where model_type='App\Models\User' and model_id in ({1}) order by model_id )) ) order by case when cself.parent_id is null and pmenu.parent_id is null then cself.sort when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort else pmenu2.sort end, case when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id else 100000*pmenu.parent_id+1000*pmenu.id+cself.id end ", '"'.ToString(), userid.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new external_menu(); i.icon = dr["icon"].ToString(); i.id = Convert.ToInt32(dr["id"]); i.psort = Convert.ToInt32(dr["psort"]); i.pid = Convert.ToInt32(dr["pid"]); i.display_name = dr["display_name"].ToString(); result.Add(i); } return result; } public List GetAllUser() { var sql = string.Format(@" select id,name from users ", '"'.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new external_user(); i.id = Convert.ToInt32(dr["id"]); i.name = dr["name"].ToString(); result.Add(i); } return result; } public external_employeeWithSelectionViewModel GetBlankItem() { var i = new external_employeeWithSelectionViewModel(); //var j = Mapper.Map>((from x in epc.GetListALLeva_performance_criteria() select x)); //i.eva_performance_criteria_id = j; return i; } public List GetDeptMapping() { var sql = string.Format(@" select orgdata.id,orgdata2.id as id2, case when orgdata2.department_name is not null then concat(orgdata2.department_name,' - ',orgdata.department_name) else orgdata.department_name end as full_dep, orgdata.department_name, orgdata.department_code,detail.parent_department_id, case when org_type_depart.department_degree_id = 1 then orgdata.department_code::int*1000 when detail.parent_department_id is not null and detail.parent_department_id>0 then orgdata2.department_code::int*1000+orgdata.department_code::int else orgdata.department_code::int*100000 end as sort_order,org_type_depart.department_degree_id from public.{0}DepartmentData{0} orgdata left join org_organization_chart_details detail on orgdata.id = detail.department_id left join public.{0}DepartmentData{0} orgdata2 on orgdata2.id = detail.parent_department_id left join public.org_type_departments as org_type_depart on orgdata.department_type_id = org_type_depart.id left join public.org_type_department_colors as org_depart_color on org_type_depart.department_degree_id = org_depart_color.id where orgdata.department_name is not null and orgdata.deleted_at is null order by case when org_type_depart.department_degree_id = 1 then orgdata.department_code::int*1000 when detail.parent_department_id is not null and detail.parent_department_id>0 then orgdata2.department_code::int*1000+orgdata.department_code::int else orgdata.department_code::int*100000 end ", '"'.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new dept_mappingViewModel(); if(dr["id"] != DBNull.Value) i.id = Convert.ToInt32(dr["id"]); if (dr["id2"] != DBNull.Value) i.id2 = Convert.ToInt32(dr["id2"]); if (dr["full_dep"] != DBNull.Value) i.full_dep= dr["full_dep"].ToString(); if (dr["department_name"] != DBNull.Value) i.department_name = dr["department_name"].ToString(); if (dr["department_code"] != DBNull.Value) i.department_code = dr["department_code"].ToString(); if (dr["parent_department_id"] != DBNull.Value) i.parent_department_id = Convert.ToInt32(dr["parent_department_id"]); if (dr["sort_order"] != DBNull.Value) i.sort_order = Convert.ToInt32(dr["sort_order"]); if (dr["department_degree_id"] != DBNull.Value) i.department_degree_id = Convert.ToInt32(dr["department_degree_id"]); result.Add(i); } return result; } public List GetWorkingRecord() { var sql = string.Format(@" select * FROM hrm_working_records where deleted_at is null ", '"'.ToString()); var para = db.GetParameterListNpgsql(); DataTable dt = db.ExecuteDataTableNpgsql(sql, para); var result = new List(); foreach (DataRow dr in dt.Rows) { var i = new working_records(); if (dr["id"] != DBNull.Value) i.id = Convert.ToInt32(dr["id"]); if (dr["employee_id"] != DBNull.Value) i.employee_id = Convert.ToInt32(dr["employee_id"]); if (dr["place"] != DBNull.Value) i.place = Convert.ToInt32(dr["place"]); if (dr["start_date"] != DBNull.Value) i.start_date = Convert.ToDateTime(dr["start_date"]); if (dr["end_date"] != DBNull.Value) i.end_date = Convert.ToDateTime(dr["end_date"]); if (dr["subject"] != DBNull.Value) i.subject = dr["subject"].ToString(); if (dr["detail"] != DBNull.Value) i.detail = dr["detail"].ToString(); result.Add(i); } return result; } } public class working_records { public int? id { get; set; } public int? employee_id { get; set; } public int? place { get; set; } public DateTime? start_date { get; set; } public DateTime? end_date { get; set; } public string subject { get; set; } public string detail { get; set; } } public class external_menu { public string icon { get; set; } public int? id { get; set; } public int? psort { get; set; } public int? pid { get; set; } public string display_name { get; set; } } public class external_user { public int? id { get; set; } public string name { get; set; } } }