แก้ไข OP 2651
This commit is contained in:
@@ -20,14 +20,14 @@ namespace TodoAPI2.Models
|
||||
public class eva_create_evaluation_detail_statusService : Ieva_create_evaluation_detail_statusService
|
||||
{
|
||||
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_statusService(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_statusViewModel>>(entities);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
@@ -77,18 +77,18 @@ namespace TodoAPI2.Models
|
||||
|
||||
public List<eva_create_evaluation_detail_statusViewModel> GetListBycreate_evaluation_id(int? create_evaluation_id)
|
||||
{
|
||||
var model = new eva_create_evaluation_detail_statusSearchModel();
|
||||
var model = new eva_create_evaluation_detail_statusSearchModel();
|
||||
model.create_evaluation_id = create_evaluation_id;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_create_evaluation_detail_statusViewModel> GetListBySearch(eva_create_evaluation_detail_statusSearchModel model)
|
||||
public List<eva_create_evaluation_detail_statusViewModel> GetListBySearch(eva_create_evaluation_detail_statusSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_create_evaluation_detail_status in _repository.Context.eva_create_evaluation_detail
|
||||
|
||||
|
||||
where 1==1
|
||||
where 1 == 1
|
||||
//&& (m_eva_create_evaluation_detail_status.id == model.id || !model.id.HasValue)
|
||||
&& (m_eva_create_evaluation_detail_status.create_evaluation_id == model.create_evaluation_id || !model.create_evaluation_id.HasValue)
|
||||
|
||||
@@ -123,10 +123,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;
|
||||
}
|
||||
@@ -142,13 +142,18 @@ namespace TodoAPI2.Models
|
||||
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
|
||||
|
||||
return Get(inserted.id);
|
||||
}
|
||||
|
||||
public eva_create_evaluation_detail_statusViewModel Update(int id, eva_create_evaluation_detail_statusInputModel model)
|
||||
{
|
||||
var existingEntity = _repository.Get(id);
|
||||
|
||||
var current_eva = (from k in _repository.Context.eva_create_evaluation
|
||||
where k.id == existingEntity.create_evaluation_id
|
||||
select k).FirstOrDefault();
|
||||
|
||||
if (existingEntity != null)
|
||||
{
|
||||
existingEntity.create_evaluation_id = model.create_evaluation_id;
|
||||
@@ -158,26 +163,31 @@ namespace TodoAPI2.Models
|
||||
existingEntity.status_supervisor1A = model.status_supervisor1A;
|
||||
existingEntity.status_supervisor2A = model.status_supervisor2A;
|
||||
|
||||
if (current_eva.employee_id == existingEntity.chief) // หัวหน้าและผู้ประเมินสูงสุด เป็นคนคนเดียวกัน
|
||||
{
|
||||
if(existingEntity.status_chief == "Y") existingEntity.status_supervisor = existingEntity.status_chief;
|
||||
}
|
||||
|
||||
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_statusInputModel> model)
|
||||
public string UpdateMultiple(List<eva_create_evaluation_detail_statusInputModel> 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.status_self = i.status_self;
|
||||
existingEntity.status_chief = i.status_chief;
|
||||
existingEntity.status_supervisor = i.status_supervisor;
|
||||
existingEntity.create_evaluation_id = i.create_evaluation_id;
|
||||
existingEntity.status_self = i.status_self;
|
||||
existingEntity.status_chief = i.status_chief;
|
||||
existingEntity.status_supervisor = i.status_supervisor;
|
||||
existingEntity.status_supervisor1A = i.status_supervisor1A;
|
||||
existingEntity.status_supervisor2A = i.status_supervisor2A;
|
||||
|
||||
@@ -192,15 +202,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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user