แก้ไข OP 2651

This commit is contained in:
Nakorn Rientrakrunchai
2020-07-21 16:08:46 +07:00
parent 13dc865ad1
commit 764cd3c398
13 changed files with 153 additions and 79 deletions

View File

@@ -20,14 +20,14 @@ namespace TodoAPI2.Models
public class eva_create_evaluation_detail_review01Service : Ieva_create_evaluation_detail_review01Service
{
private IBaseRepository2<eva_create_evaluation_detailEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private IMyDatabase db;
private Iexternal_linkageService ext;
public eva_create_evaluation_detail_review01Service(IBaseRepository2<eva_create_evaluation_detailEntity, int> repository, IMyDatabase mydb, Iexternal_linkageService inext)
{
_repository = repository;
db = mydb;
ext = inext;
db = mydb;
ext = inext;
}
#region Private Functions
@@ -47,7 +47,7 @@ namespace TodoAPI2.Models
{
return Mapper.Map<List<eva_create_evaluation_detail_review01ViewModel>>(entities);
}
#endregion
#region Public Functions
@@ -79,12 +79,12 @@ namespace TodoAPI2.Models
public List<eva_create_evaluation_detail_review01ViewModel> GetListBycreate_evaluation_id(int? create_evaluation_id)
{
var model = new eva_create_evaluation_detail_review01SearchModel();
var model = new eva_create_evaluation_detail_review01SearchModel();
model.create_evaluation_id = create_evaluation_id;
return GetListBySearch(model);
}
public List<eva_create_evaluation_detail_review01ViewModel> GetListBySearch(eva_create_evaluation_detail_review01SearchModel model)
public List<eva_create_evaluation_detail_review01ViewModel> GetListBySearch(eva_create_evaluation_detail_review01SearchModel model)
{
var data = (
from m_eva_create_evaluation_detail_review01 in _repository.Context.eva_create_evaluation_detail
@@ -94,7 +94,7 @@ namespace TodoAPI2.Models
from fk_external_linkageResult3 in external_linkageResult3.DefaultIfEmpty()
where 1==1
where 1 == 1
//&& (m_eva_create_evaluation_detail_review01.id == model.id || !model.id.HasValue)
&& (m_eva_create_evaluation_detail_review01.create_evaluation_id == model.create_evaluation_id || !model.create_evaluation_id.HasValue)
@@ -129,10 +129,10 @@ namespace TodoAPI2.Models
int? newkey = 0;
var x = (from i in _repository.Context.eva_create_evaluation_detail
orderby i.id descending
select i).Take(1).ToList();
orderby i.id descending
select i).Take(1).ToList();
if(x.Count > 0)
if (x.Count > 0)
{
newkey = x[0].id + 1;
}
@@ -148,7 +148,7 @@ namespace TodoAPI2.Models
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
@@ -161,6 +161,10 @@ namespace TodoAPI2.Models
where k.id == model.id
select k).FirstOrDefault();
var current_eva = (from k in _repository.Context.eva_create_evaluation
where k.id == current_detail.create_evaluation_id
select k).FirstOrDefault();
if (current_detail.status_chief == "Y")
{
throw new Exception("ผู้ประเมิน ส่งแบบประเมินไปแล้ว บันทึกไม่ได้");
@@ -172,28 +176,35 @@ namespace TodoAPI2.Models
existingEntity.supervisor1_remark = model.supervisor1_remark;
existingEntity.supervisor1_date = DateTime.Now;
if (current_eva.employee_id == current_detail.chief) // หัวหน้าและผู้ประเมินสูงสุด เป็นคนคนเดียวกัน
{
existingEntity.supervisor2 = model.supervisor1;
existingEntity.supervisor2_result = "Y";
existingEntity.supervisor2_remark = model.supervisor1_remark;
existingEntity.supervisor2_date = DateTime.Now;
}
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_create_evaluation_detail_review01InputModel> model)
public string UpdateMultiple(List<eva_create_evaluation_detail_review01InputModel> 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.create_evaluation_id = i.create_evaluation_id;
existingEntity.supervisor1 = i.supervisor1;
existingEntity.create_evaluation_id = i.create_evaluation_id;
existingEntity.supervisor1 = i.supervisor1;
existingEntity.supervisor1_result = null; //i.supervisor1_result;
existingEntity.supervisor1_remark = i.supervisor1_remark;
existingEntity.supervisor1_date = i.supervisor1_date;
existingEntity.supervisor1_remark = i.supervisor1_remark;
existingEntity.supervisor1_date = i.supervisor1_date;
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
@@ -206,15 +217,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();
}