ปรับโครงสร้างระบบ ให้รองรับ การไปช่วยปฏิบัติงาน

This commit is contained in:
Nakorn Rientrakrunchai
2021-03-09 18:46:05 +07:00
parent fcc5146085
commit 2952c1fc2a
40 changed files with 2188 additions and 1176 deletions

View File

@@ -21,6 +21,8 @@ namespace TodoAPI2.Models
[MaxLength(255)]
public string thegroup { get; set; }
public int? main_dept_id { get; set; }
public decimal? percentage { get; set; }
}
}

View File

@@ -20,6 +20,10 @@ namespace TodoAPI2.Models
public string thegroup { get; set; }
public int? main_dept_id { get; set; }
public decimal? percentage { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -20,14 +20,16 @@ namespace TodoAPI2.Models
public class eva_evaluation_groupService : Ieva_evaluation_groupService
{
private IBaseRepository<eva_evaluation_groupEntity, Guid> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
public eva_evaluation_groupService(IBaseRepository<eva_evaluation_groupEntity, Guid> repository, IMyDatabase mydb, Iexternal_linkageService inext)
public eva_evaluation_groupService(IBaseRepository<eva_evaluation_groupEntity, Guid> repository, IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService inemp)
{
_repository = repository;
db = mydb;
ext = inext;
db = mydb;
ext = inext;
emp = inemp;
}
#region Private Functions
@@ -47,7 +49,7 @@ namespace TodoAPI2.Models
{
return Mapper.Map<List<eva_evaluation_groupViewModel>>(entities);
}
private List<eva_evaluation_groupEntity> GetListWithoutBase64Fields(IQueryable<eva_evaluation_groupEntity> listQuery)
{
return listQuery.Select(c => new eva_evaluation_groupEntity()
@@ -65,6 +67,21 @@ namespace TodoAPI2.Models
#region Public Functions
#region Query Functions
private List<external_linkageViewModel> getMainDept()
{
var a = emp.GetDeptMapping().Where(x => !x.id2.HasValue);
var data = new List<external_linkageViewModel>();
foreach(var i in a)
{
var n = new external_linkageViewModel();
n.external_id = i.id;
n.external_name = i.department_name;
n.external_code = i.department_code;
data.Add(n);
}
return data;
}
public eva_evaluation_groupViewModel Get(Guid id)
{
var entity = _repository.Get(id);
@@ -75,6 +92,7 @@ namespace TodoAPI2.Models
{
var entity = _repository.Get(id);
var i = Mapper.Map<eva_evaluation_groupWithSelectionViewModel>(entity);
i.item_main_dept_id = getMainDept();
return i;
@@ -82,23 +100,38 @@ namespace TodoAPI2.Models
public eva_evaluation_groupWithSelectionViewModel GetBlankItem()
{
var i = new eva_evaluation_groupWithSelectionViewModel();
i.item_main_dept_id = getMainDept();
return i;
}
public List<eva_evaluation_groupViewModel> GetListBycode(string code)
{
var model = new eva_evaluation_groupSearchModel();
model.code = code;
return GetListBySearch(model);
}
public List<eva_evaluation_groupViewModel> GetListALLeva_evaluation_group()
{
var data = (
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
orderby m_eva_evaluation_group.created descending
join fk_external_linkage3 in getMainDept() on m_eva_evaluation_group.main_dept_id equals fk_external_linkage3.id
into external_linkageResult3
from fk_external_linkageResult3 in external_linkageResult3.DefaultIfEmpty()
orderby m_eva_evaluation_group.code
select new eva_evaluation_groupViewModel()
{
id = m_eva_evaluation_group.id,
code = m_eva_evaluation_group.code,
thegroup = m_eva_evaluation_group.thegroup,
main_dept_id = m_eva_evaluation_group.main_dept_id,
percentage = m_eva_evaluation_group.percentage,
main_dept_id_external_linkage_external_name = fk_external_linkageResult3.external_name,
isActive = m_eva_evaluation_group.isActive,
Created = m_eva_evaluation_group.created,
@@ -109,48 +142,30 @@ namespace TodoAPI2.Models
return data;
}
public List<eva_evaluation_groupViewModel> GetListBycode(string code)
public List<eva_evaluation_groupViewModel> GetListBySearch(eva_evaluation_groupSearchModel model)
{
var data = (
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
join fk_external_linkage3 in getMainDept() on m_eva_evaluation_group.main_dept_id equals fk_external_linkage3.id
into external_linkageResult3
from fk_external_linkageResult3 in external_linkageResult3.DefaultIfEmpty()
where m_eva_evaluation_group.code == code || string.IsNullOrEmpty(code)
orderby m_eva_evaluation_group.created descending
select new eva_evaluation_groupViewModel()
{
id = m_eva_evaluation_group.id,
code = m_eva_evaluation_group.code,
thegroup = m_eva_evaluation_group.thegroup,
isActive = m_eva_evaluation_group.isActive,
Created = m_eva_evaluation_group.created,
Updated = m_eva_evaluation_group.updated
}
).ToList();
return data;
}
public List<eva_evaluation_groupViewModel> GetListBySearch(eva_evaluation_groupSearchModel model)
{
var data = (
from m_eva_evaluation_group in _repository.Context.eva_evaluation_group
where 1==1
where 1 == 1
&& (m_eva_evaluation_group.code == model.code || string.IsNullOrEmpty(model.code))
orderby m_eva_evaluation_group.created descending
orderby m_eva_evaluation_group.code
select new eva_evaluation_groupViewModel()
{
id = m_eva_evaluation_group.id,
code = m_eva_evaluation_group.code,
thegroup = m_eva_evaluation_group.thegroup,
main_dept_id = m_eva_evaluation_group.main_dept_id,
percentage = m_eva_evaluation_group.percentage,
main_dept_id_external_linkage_external_name = fk_external_linkageResult3.external_name,
isActive = m_eva_evaluation_group.isActive,
Created = m_eva_evaluation_group.created,
@@ -172,7 +187,7 @@ namespace TodoAPI2.Models
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
@@ -183,26 +198,29 @@ namespace TodoAPI2.Models
{
existingEntity.code = model.code;
existingEntity.thegroup = model.thegroup;
existingEntity.main_dept_id = model.main_dept_id;
existingEntity.percentage = model.percentage;
var updated = _repository.Update(id, existingEntity);
return Get(updated.id);
}
else
throw new NotificationException("No data to update");
throw new NotificationException("No data to update");
}
public string UpdateMultiple(List<eva_evaluation_groupInputModel> model)
public string UpdateMultiple(List<eva_evaluation_groupInputModel> model)
{
foreach(var i in model)
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.code = i.code;
existingEntity.thegroup = i.thegroup;
existingEntity.code = i.code;
existingEntity.thegroup = i.thegroup;
existingEntity.main_dept_id = i.main_dept_id;
existingEntity.percentage = i.percentage;
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
@@ -215,15 +233,15 @@ namespace TodoAPI2.Models
_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
}
}
}
_repository.Context.SaveChanges();
_repository.Context.SaveChanges();
return model.Count().ToString();
}

View File

@@ -18,6 +18,10 @@ namespace TodoAPI2.Models
public string thegroup { get; set; }
public int? main_dept_id { get; set; }
public decimal? percentage { get; set; }
public string main_dept_id_external_linkage_external_name { get; set; }
}
}

View File

@@ -7,6 +7,6 @@ namespace TodoAPI2.Models
{
public class eva_evaluation_groupWithSelectionViewModel: eva_evaluation_groupViewModel
{
public List<external_linkageViewModel> item_main_dept_id { get; set; }
}
}