ปรับปรุง คนที่ได้สิทธิพิเศษ ให้ดูรายชื่อได้ทั้งเนติ

This commit is contained in:
nakorn
2021-10-16 21:51:16 +07:00
parent ac0e022966
commit df7d36b06b
28 changed files with 2660 additions and 30 deletions

View File

@@ -71,6 +71,9 @@ namespace TodoAPI2.Models
public eva_create_evaluation_detail_firstdocViewModel Get(int id, int? emp_id)
{
object special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToArray();
var allemp = emp.GetListByemployee_type(null, null);
var endDate = (from m_eva_create_evaluation_detail_agreement in _repository.Context.eva_create_evaluation_detail
@@ -148,7 +151,8 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_agreement.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_agreement.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
m_eva_create_evaluation_detail_agreement.employee_id,
m_eva_create_evaluation_detail_agreement.status_self_a,
m_eva_create_evaluation_detail_agreement.status_chief_a
m_eva_create_evaluation_detail_agreement.status_chief_a,
special_person
),
role_desc = getRoleName(emp_id,
@@ -159,7 +163,9 @@ namespace TodoAPI2.Models
fk_eva_create_evaluationResult10.supervisor2_id,
m_eva_create_evaluation_detail_agreement.employee_id,
m_eva_create_evaluation_detail_agreement.status_self_a,
m_eva_create_evaluation_detail_agreement.status_chief_a),
m_eva_create_evaluation_detail_agreement.status_chief_a,
special_person
),
isActive = m_eva_create_evaluation_detail_agreement.isActive,
Created = m_eva_create_evaluation_detail_agreement.created,
@@ -171,7 +177,7 @@ namespace TodoAPI2.Models
}
private string getRoleCode(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, int? self,
string status_self_a, string status_chief_a)
string status_self_a, string status_chief_a, object special_person)
{
if (emp_id == self && status_self_a != "Y") return ""; // ผู้รับการประเมิน
if (self == chief && emp_id == chief && status_chief_a != "Y") return "1";
@@ -179,6 +185,7 @@ namespace TodoAPI2.Models
if (self == supervisor2 && emp_id == supervisor2 && status_chief_a == "Y") return "2";
if (self == supervisor1A && emp_id == supervisor1A && status_chief_a == "Y") return "3";
if (self == supervisor2A && emp_id == supervisor2A && status_chief_a == "Y") return "4";
if (((int?[])special_person).Contains(emp_id)) return "99";
if (emp_id == chief) return "1";
else if (emp_id == supervisor1) return "1";
@@ -189,7 +196,7 @@ namespace TodoAPI2.Models
}
private string getRoleName(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, int? self,
string status_self_a, string status_chief_a)
string status_self_a, string status_chief_a, object special_person)
{
if (emp_id == self && status_self_a != "Y") return ""; // ผู้รับการประเมิน
if (self == chief && emp_id == chief && status_chief_a != "Y") return "ผู้ประเมิน";
@@ -197,6 +204,7 @@ namespace TodoAPI2.Models
if (self == supervisor2 && emp_id == supervisor2 && status_chief_a == "Y") return "ผู้ประเมินสูงสุด";
if (self == supervisor1A && emp_id == supervisor1A && status_chief_a == "Y") return "ผู้บังคับบัญชาเหนือขึ้นไป";
if (self == supervisor2A && emp_id == supervisor2A && status_chief_a == "Y") return "ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง (สูงสุด)";
if (((int?[])special_person).Contains(emp_id)) return "ผู้ตรวจสอบ";
if (emp_id == chief) return "ผู้ประเมิน";
else if (emp_id == supervisor1) return "ผู้ประเมิน";
@@ -223,11 +231,14 @@ namespace TodoAPI2.Models
var entity = Get(id, emp_id);
var i = Mapper.Map<eva_create_evaluation_detail_firstdocWithSelectionViewModel>(entity);
var special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToList();
var dep = (from x in emp.GetAllEmployee()
where x.id == emp_id
where x.id == emp_id
select x.department_id).FirstOrDefault();
var alldep = (from x in emp.GetDeptMapping()
where x.id == dep || x.id2 == dep
where x.id == dep || x.id2 == dep || special_person.Contains(emp_id)
select x.id);
var option_1 = new external_linkageViewModel();
option_1.id_guid = Guid.Empty;
@@ -243,6 +254,7 @@ namespace TodoAPI2.Models
|| y.eva_employee_id == emp_id
|| y.supervisor1_id == emp_id
|| y.supervisor2_id == emp_id
|| special_person.Contains(emp_id)
select y.employee_id).ToList();
i.item_org_id = (from q in ext.GetDepartmentData() where alldep.Contains(q.id) select q).ToList();
@@ -268,11 +280,14 @@ namespace TodoAPI2.Models
{
var i = new eva_create_evaluation_detail_firstdocWithSelectionViewModel();
var special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToList();
var dep = (from x in emp.GetAllEmployee()
where x.id == emp_id
select x.department_id).FirstOrDefault();
var alldep = (from x in emp.GetDeptMapping()
where x.id == dep || x.id2 == dep
where x.id == dep || x.id2 == dep || special_person.Contains(emp_id)
select x.id);
var option_1 = new external_linkageViewModel();
option_1.id_guid = Guid.Empty;
@@ -288,6 +303,7 @@ namespace TodoAPI2.Models
|| y.eva_employee_id == emp_id
|| y.supervisor1_id == emp_id
|| y.supervisor2_id == emp_id
|| special_person.Contains(emp_id)
select y.employee_id).ToList();
i.item_org_id = (from q in ext.GetDepartmentData() where alldep.Contains(q.id) select q).ToList();
@@ -334,6 +350,9 @@ namespace TodoAPI2.Models
public List<eva_create_evaluation_detail_firstdocViewModel> GetListBySearch(eva_create_evaluation_detail_firstdocSearchModel model, int? emp_id)
{
object special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToArray();
if (string.IsNullOrEmpty(model.evaluation_round_search))
{
model.evaluation_round_search = (from x in _repository.Context.eva_performance_plan
@@ -385,7 +404,7 @@ namespace TodoAPI2.Models
&& (fk_external_employee.department_id == model.org_id || !model.org_id.HasValue)
&& (fk_external_employee.id == model.employee_id || !model.employee_id.HasValue)
&& (string.IsNullOrEmpty(model.evaluation_round_search) || fk_planResult.id == Guid.Parse(model.evaluation_round_search))
&& (m_eva_create_evaluation_detail_agreement.employee_id == emp_id || m_eva_create_evaluation_detail_agreement.chief == emp_id)
&& (m_eva_create_evaluation_detail_agreement.employee_id == emp_id || m_eva_create_evaluation_detail_agreement.chief == emp_id || ((int?[])special_person).Contains(emp_id))
orderby
fk_sort_depResult2.external_code,
@@ -439,7 +458,9 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_agreement.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_agreement.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
m_eva_create_evaluation_detail_agreement.employee_id,
m_eva_create_evaluation_detail_agreement.status_self_a,
m_eva_create_evaluation_detail_agreement.status_chief_a),
m_eva_create_evaluation_detail_agreement.status_chief_a,
special_person
),
role_desc = getRoleName(emp_id,
m_eva_create_evaluation_detail_agreement.chief,
@@ -449,7 +470,9 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_agreement.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_agreement.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
m_eva_create_evaluation_detail_agreement.employee_id,
m_eva_create_evaluation_detail_agreement.status_self_a,
m_eva_create_evaluation_detail_agreement.status_chief_a),
m_eva_create_evaluation_detail_agreement.status_chief_a,
special_person
),
isActive = m_eva_create_evaluation_detail_agreement.isActive,
Created = m_eva_create_evaluation_detail_agreement.created,

View File

@@ -74,6 +74,9 @@ namespace TodoAPI2.Models
public eva_create_evaluation_detail_processWithSelectionViewModel Get(int id, int? emp_id, string path)
{
object special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToArray();
var allemp = emp.GetListByemployee_type(null, null);
var plan_id = (from m_eva_create_evaluation_detail_process in _repository.Context.eva_create_evaluation_detail
@@ -181,14 +184,16 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_process.eva_employee_id.HasValue ? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id,
m_eva_create_evaluation_detail_process.supervisor1_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id,
m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
path),
path,
special_person),
role_desc = getRoleName(emp_id, m_eva_create_evaluation_detail_process.chief,
m_eva_create_evaluation_detail_process.chief,
m_eva_create_evaluation_detail_process.eva_employee_id.HasValue ? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id,
m_eva_create_evaluation_detail_process.supervisor1_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id,
m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
path),
path,
special_person),
remark_hrm_work_record = fk_external_employee.remark_hrm_work_record
+ GetWorkTimeText(fk_external_employee.packing_date, end_date),
@@ -228,12 +233,15 @@ namespace TodoAPI2.Models
{
var item = Get(id, emp_id, path);
var special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToList();
var dep = (from x in emp.GetAllEmployee()
where x.id == emp_id
select x.department_id).FirstOrDefault();
var alldep = (from x in emp.GetDeptMapping()
where x.id == dep || x.id2 == dep
select x.id);
where x.id == dep || x.id2 == dep || special_person.Contains(emp_id)
select x.id);
var option_1 = new external_linkageViewModel();
option_1.id_guid = Guid.Empty;
option_1.external_name = "ทั้งหมด";
@@ -248,6 +256,7 @@ namespace TodoAPI2.Models
|| y.eva_employee_id == emp_id
|| y.supervisor1_id == emp_id
|| y.supervisor2_id == emp_id
|| special_person.Contains(emp_id)
select y.employee_id).ToList();
item.item_org_id = (from i in ext.GetDepartmentData() where alldep.Contains(i.id) select i).ToList();
@@ -275,11 +284,14 @@ namespace TodoAPI2.Models
public eva_create_evaluation_detail_processWithSelectionViewModel GetBlankItemWithEmp(int? emp_id)
{
var i = new eva_create_evaluation_detail_processWithSelectionViewModel();
var special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToList();
var dep = (from x in emp.GetAllEmployee()
where x.id == emp_id
select x.department_id).FirstOrDefault();
var alldep = (from x in emp.GetDeptMapping()
where x.id == dep || x.id2 == dep
where x.id == dep || x.id2 == dep || special_person.Contains(emp_id)
select x.id);
var option_1 = new external_linkageViewModel();
option_1.id_guid = Guid.Empty;
@@ -296,6 +308,7 @@ namespace TodoAPI2.Models
|| y.eva_employee_id == emp_id
|| y.supervisor1_id == emp_id
|| y.supervisor2_id == emp_id
|| special_person.Contains(emp_id)
select y.employee_id).ToList();
i.item_org_id = (from q in ext.GetDepartmentData() where alldep.Contains(q.id) select q).ToList();
@@ -352,6 +365,9 @@ namespace TodoAPI2.Models
public List<eva_create_evaluation_detail_processViewModel> GetListBySearch(eva_create_evaluation_detail_processSearchModel model, int? emp_id, string path)
{
object special_person = (from x in _repository.Context.eva_setup_permission
select x.employee_id).ToArray();
if (string.IsNullOrEmpty(model.evaluation_round_search))
{
model.evaluation_round_search = (from x in _repository.Context.eva_performance_plan
@@ -406,6 +422,7 @@ namespace TodoAPI2.Models
|| (((m_eva_create_evaluation_detail_process.eva_employee_id.HasValue ? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id)).HasValue && emp_id == (m_eva_create_evaluation_detail_process.eva_employee_id.HasValue ? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id))
|| ((m_eva_create_evaluation_detail_process.supervisor1_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id).HasValue && emp_id == (m_eva_create_evaluation_detail_process.supervisor1_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id))
|| ((m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id).HasValue && emp_id == (m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id))
|| ((int?[])special_person).Contains(emp_id)
)
&& (!model.employee_id.HasValue || m_eva_create_evaluation_detail_process.employee_id == model.employee_id)
@@ -450,7 +467,8 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_process.eva_employee_id.HasValue? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id,
m_eva_create_evaluation_detail_process.supervisor1_id.HasValue? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id,
m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
m_eva_create_evaluation_detail_process.status_chief
m_eva_create_evaluation_detail_process.status_chief,
special_person
),
role_desc = getRoleName(emp_id, m_eva_create_evaluation_detail_process.chief,
@@ -458,7 +476,8 @@ namespace TodoAPI2.Models
m_eva_create_evaluation_detail_process.eva_employee_id.HasValue ? m_eva_create_evaluation_detail_process.eva_employee_id : fk_eva_create_evaluationResult10.employee_id,
m_eva_create_evaluation_detail_process.supervisor1_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor1_id : fk_eva_create_evaluationResult10.supervisor1_id,
m_eva_create_evaluation_detail_process.supervisor2_id.HasValue ? m_eva_create_evaluation_detail_process.supervisor2_id : fk_eva_create_evaluationResult10.supervisor2_id,
path),
path,
special_person),
status_self_click_date = m_eva_create_evaluation_detail_process.status_self_click_date,
status_chief_click_date = m_eva_create_evaluation_detail_process.status_chief_click_date,
@@ -486,7 +505,7 @@ namespace TodoAPI2.Models
return "";
}
private string getRoleCode(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string path)
private string getRoleCode(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string path, object special_person)
{
if ((emp_id == chief || emp_id == supervisor1) && chief == supervisor2 && path == "d2") return "2";
else if (emp_id == chief) return "1";
@@ -494,10 +513,11 @@ namespace TodoAPI2.Models
else if (emp_id == supervisor2) return "2";
else if (emp_id == supervisor1A) return "3";
else if (emp_id == supervisor2A) return "4";
if (((int?[])special_person).Contains(emp_id)) return "99";
return "";
}
private string getRoleCodeSearch(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string status_chief)
private string getRoleCodeSearch(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string status_chief, object special_person)
{
if ((emp_id == chief || emp_id == supervisor1) && chief == supervisor2 && status_chief=="Y") return "2";
else if (emp_id == chief) return "1";
@@ -505,10 +525,11 @@ namespace TodoAPI2.Models
else if (emp_id == supervisor2) return "2";
else if (emp_id == supervisor1A) return "3";
else if (emp_id == supervisor2A) return "4";
if (((int?[])special_person).Contains(emp_id)) return "99";
return "";
}
private string getRoleName(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string path)
private string getRoleName(int? emp_id, int? chief, int? supervisor1, int? supervisor2, int? supervisor1A, int? supervisor2A, string path, object special_person)
{
if ((emp_id == chief || emp_id == supervisor1) && chief == supervisor2 && path == "d2") return "ผู้ประเมินสูงสุด";
else if (emp_id == chief) return "ผู้ประเมิน";
@@ -516,6 +537,7 @@ namespace TodoAPI2.Models
else if (emp_id == supervisor2) return "ผู้ประเมินสูงสุด";
else if (emp_id == supervisor1A) return "ผู้บังคับบัญชาเหนือขึ้นไป";
else if (emp_id == supervisor2A) return "ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง (สูงสุด)";
if (((int?[])special_person).Contains(emp_id)) return "ผู้ตรวจสอบ";
return "";
}

View File

@@ -0,0 +1,32 @@
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;
namespace TodoAPI2.Models
{
public interface Ieva_setup_permissionService : IBaseService2<Guid, eva_setup_permissionInputModel, eva_setup_permissionViewModel>
{
new eva_setup_permissionViewModel Insert(eva_setup_permissionInputModel model, bool is_force_save);
new eva_setup_permissionViewModel Update(Guid id, eva_setup_permissionInputModel model, bool is_force_save);
List<eva_setup_permissionViewModel> GetListByremark(string remark);
List<eva_setup_permissionViewModel> GetListBySearch(eva_setup_permissionSearchModel model);
string UpdateMultiple(List<eva_setup_permissionInputModel> model, bool is_force_save);
eva_setup_permissionWithSelectionViewModel GetWithSelection(Guid id);
eva_setup_permissionWithSelectionViewModel GetBlankItem();
void RefreshAutoFieldOfAllData();
eva_setup_permissionEntity GetEntity(Guid id);
DataContext GetContext();
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using System.IO;
namespace TodoAPI2.Models
{
public class eva_setup_permissionEntity : BaseEntity2<Guid>
{
public int? employee_id { get; set; }
[MaxLength(4000)]
public string remark { get; set; }
public void SetAutoField(DataContext context)
{
}
public void DoAfterInsertUpdate(DataContext context)
{
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_setup_permissionInputModel
{
public Guid? id { get; set; }
public int? employee_id { get; set; }
public string remark { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_setup_permissionReportRequestModel : eva_setup_permissionSearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_setup_permissionSearchModel
{
public Guid id { get; set; }
public string remark { get; set; }
}
}

View File

@@ -0,0 +1,279 @@
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;
namespace TodoAPI2.Models
{
public class eva_setup_permissionService : Ieva_setup_permissionService
{
private IBaseRepository2<eva_setup_permissionEntity, Guid> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
public eva_setup_permissionService(IBaseRepository2<eva_setup_permissionEntity, Guid> repository, IMyDatabase mydb,
Iexternal_linkageService inext, Iexternal_employeeService inemp)
{
_repository = repository;
db = mydb;
ext = inext;
emp = inemp;
}
#region Private Functions
private eva_setup_permissionEntity GetEntity(eva_setup_permissionInputModel model)
{
return Mapper.Map<eva_setup_permissionEntity>(model);
}
private List<eva_setup_permissionEntity> GetEntityList(List<eva_setup_permissionInputModel> models)
{
return Mapper.Map<List<eva_setup_permissionEntity>>(models);
}
private eva_setup_permissionViewModel GetDto(eva_setup_permissionEntity entity)
{
return Mapper.Map<eva_setup_permissionViewModel>(entity);
}
private List<eva_setup_permissionViewModel> GetDtoList(List<eva_setup_permissionEntity> entities)
{
return Mapper.Map<List<eva_setup_permissionViewModel>>(entities);
}
#endregion
#region Public Functions
#region Query Functions
public eva_setup_permissionViewModel Get(Guid id)
{
var entity = _repository.Get(id);
return GetDto(entity);
}
public eva_setup_permissionEntity GetEntity(Guid id)
{
var entity = _repository.Get(id);
return entity;
}
public DataContext GetContext()
{
return _repository.Context;
}
public eva_setup_permissionWithSelectionViewModel GetWithSelection(Guid id)
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_setup_permissionWithSelectionViewModel>(entity);
i.item_employee_id = (from x in emp.GetAllEmployee() select x).ToList();
return i;
}
public eva_setup_permissionWithSelectionViewModel GetBlankItem()
{
var i = new eva_setup_permissionWithSelectionViewModel();
i.item_employee_id = (from x in emp.GetAllEmployee() select x).ToList();
return i;
}
public List<eva_setup_permissionViewModel> GetListByremark(string remark)
{
var model = new eva_setup_permissionSearchModel();
model.remark = remark;
return GetListBySearch(model);
}
public List<eva_setup_permissionViewModel> GetListBySearch(eva_setup_permissionSearchModel model)
{
var data = (
from m_eva_setup_permission in _repository.Context.eva_setup_permission
join fk_external_linkage1 in emp.GetAllEmployee() on m_eva_setup_permission.employee_id equals fk_external_linkage1.id
into external_linkageResult1
from fk_external_linkageResult1 in external_linkageResult1.DefaultIfEmpty()
where
1 == 1
&& (string.IsNullOrEmpty(model.remark) || m_eva_setup_permission.remark.Contains(model.remark))
orderby m_eva_setup_permission.created descending
select new eva_setup_permissionViewModel()
{
id = m_eva_setup_permission.id,
employee_id = m_eva_setup_permission.employee_id,
remark = m_eva_setup_permission.remark,
employee_id_external_linkage_external_name = fk_external_linkageResult1.fullname,
isActive = m_eva_setup_permission.isActive,
Created = m_eva_setup_permission.created,
Updated = m_eva_setup_permission.updated
}
).Take(1000).ToList();
return data;
}
#endregion
#region Manipulation Functions
public eva_setup_permissionViewModel Insert(eva_setup_permissionInputModel model, bool is_force_save)
{
var entity = GetEntity(model);
entity.id = Guid.NewGuid();
entity.SetAutoField(_repository.Context);
if (is_force_save)
{
var inserted = _repository.Insert(entity);
entity.DoAfterInsertUpdate(_repository.Context);
return Get(inserted.id);
}
else
{
_repository.InsertWithoutCommit(entity);
entity.DoAfterInsertUpdate(_repository.Context);
return Mapper.Map<eva_setup_permissionViewModel>(entity);
}
}
public eva_setup_permissionViewModel Update(Guid id, eva_setup_permissionInputModel model, bool is_force_save)
{
var existingEntity = _repository.Get(id);
if (existingEntity != null)
{
existingEntity.employee_id = model.employee_id;
existingEntity.remark = model.remark;
existingEntity.SetAutoField(_repository.Context);
if (is_force_save)
{
var updated = _repository.Update(id, existingEntity);
existingEntity.DoAfterInsertUpdate(_repository.Context);
return Get(updated.id);
}
else
{
_repository.UpdateWithoutCommit(id, existingEntity);
existingEntity.DoAfterInsertUpdate(_repository.Context);
return Mapper.Map<eva_setup_permissionViewModel>(existingEntity);
}
}
else
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_setup_permissionInputModel> model, bool is_force_save)
{
foreach(var i in model)
{
if (i.active_mode == "1" && i.id.HasValue) // update
{
var existingEntity = _repository.Get(i.id.Value);
if (existingEntity != null)
{
existingEntity.employee_id = i.employee_id;
existingEntity.remark = i.remark;
existingEntity.SetAutoField(_repository.Context);
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
}
}
else if (i.active_mode == "1" && !i.id.HasValue) // add
{
var entity = GetEntity(i);
entity.id = Guid.NewGuid();
entity.SetAutoField(_repository.Context);
_repository.InsertWithoutCommit(entity);
}
else if (i.active_mode == "0" && i.id.HasValue) // remove
{
_repository.DeleteWithoutCommit(i.id.Value);
}
else if (i.active_mode == "0" && !i.id.HasValue)
{
// nothing to do
}
}
if (is_force_save)
{
_repository.Context.SaveChanges();
}
return model.Count().ToString();
}
public eva_setup_permissionViewModel SetAsActive(Guid id)
{
var updated = _repository.SetAsActive(id);
return Get(updated.id);
}
public eva_setup_permissionViewModel SetAsInactive(Guid id)
{
var updated = _repository.SetAsInActive(id);
return Get(updated.id);
}
public void Delete(Guid id)
{
_repository.Delete(id);
return;
}
public void RefreshAutoFieldOfAllData()
{
var all_items = from i in _repository.Context.eva_setup_permission
select i;
foreach (var item in all_items)
{
item.SetAutoField(_repository.Context);
}
_repository.Context.SaveChanges();
}
private Dictionary<string,string> GetLookupForLog()
{
var i = new Dictionary<string, string>();
i.Add("employee_id", "ชื่อพนักงาน");
i.Add("employee_id_external_linkage_external_name", "ชื่อพนักงาน");
i.Add("remark", "หมายเหตุ");
return i;
}
#endregion
#region Match Item
#endregion
#endregion
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class eva_setup_permissionViewModel : BaseViewModel2<Guid>
{
public int? employee_id { get; set; }
public string remark { get; set; }
public string employee_id_external_linkage_external_name { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class eva_setup_permissionWithSelectionViewModel: eva_setup_permissionViewModel
{
public List<external_employeeViewModel> item_employee_id { get; set; }
}
}