รวม code ส่งเข้า ZD
This commit is contained in:
@@ -20,14 +20,14 @@ namespace TodoAPI2.Models
|
||||
public class eva_evaluation_achievementService : Ieva_evaluation_achievementService
|
||||
{
|
||||
private IBaseRepository2<eva_evaluation_achievementEntity, int> _repository;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
private IMyDatabase db;
|
||||
private Iexternal_linkageService ext;
|
||||
|
||||
public eva_evaluation_achievementService(IBaseRepository2<eva_evaluation_achievementEntity, 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_evaluation_achievementViewModel>>(entities);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
@@ -77,12 +77,12 @@ namespace TodoAPI2.Models
|
||||
|
||||
public List<eva_evaluation_achievementViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id)
|
||||
{
|
||||
var model = new eva_evaluation_achievementSearchModel();
|
||||
var model = new eva_evaluation_achievementSearchModel();
|
||||
model.create_evaluation_detail_id = create_evaluation_detail_id;
|
||||
return GetListBySearch(model);
|
||||
}
|
||||
|
||||
public List<eva_evaluation_achievementViewModel> GetListBySearch(eva_evaluation_achievementSearchModel model)
|
||||
public List<eva_evaluation_achievementViewModel> GetListBySearch(eva_evaluation_achievementSearchModel model)
|
||||
{
|
||||
var data = (
|
||||
from m_eva_evaluation_achievement in _repository.Context.eva_evaluation_achievement
|
||||
@@ -92,11 +92,11 @@ namespace TodoAPI2.Models
|
||||
from fk_eva_create_evaluation_detailResult1 in eva_create_evaluation_detailResult1.DefaultIfEmpty()
|
||||
|
||||
|
||||
where 1==1
|
||||
where 1 == 1
|
||||
&& (m_eva_evaluation_achievement.create_evaluation_detail_id == model.create_evaluation_detail_id || !model.create_evaluation_detail_id.HasValue)
|
||||
|
||||
|
||||
orderby m_eva_evaluation_achievement.achievement
|
||||
orderby m_eva_evaluation_achievement.achievement
|
||||
select new eva_evaluation_achievementViewModel()
|
||||
{
|
||||
id = m_eva_evaluation_achievement.id,
|
||||
@@ -108,6 +108,12 @@ namespace TodoAPI2.Models
|
||||
|
||||
create_evaluation_detail_id_eva_create_evaluation_detail_create_evaluation_id = fk_eva_create_evaluation_detailResult1.create_evaluation_id,
|
||||
|
||||
target_score1 = m_eva_evaluation_achievement.target_score1,
|
||||
target_score2 = m_eva_evaluation_achievement.target_score2,
|
||||
target_score3 = m_eva_evaluation_achievement.target_score3,
|
||||
target_score4 = m_eva_evaluation_achievement.target_score4,
|
||||
target_score5 = m_eva_evaluation_achievement.target_score5,
|
||||
|
||||
isActive = m_eva_evaluation_achievement.isActive,
|
||||
Created = m_eva_evaluation_achievement.created,
|
||||
Updated = m_eva_evaluation_achievement.updated
|
||||
@@ -126,10 +132,10 @@ namespace TodoAPI2.Models
|
||||
int? newkey = 0;
|
||||
|
||||
var x = (from i in _repository.Context.eva_evaluation_achievement
|
||||
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;
|
||||
}
|
||||
@@ -143,6 +149,7 @@ namespace TodoAPI2.Models
|
||||
entity.id = GetNewPrimaryKey();
|
||||
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_achievement
|
||||
where i.create_evaluation_detail_id == model.create_evaluation_detail_id
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum + model.weight > 100)
|
||||
@@ -159,17 +166,18 @@ namespace TodoAPI2.Models
|
||||
}
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
|
||||
|
||||
return Get(inserted.id);
|
||||
}
|
||||
|
||||
public eva_evaluation_achievementViewModel Update(int id, eva_evaluation_achievementInputModel model)
|
||||
{
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_achievement
|
||||
where i.create_evaluation_detail_id == model.create_evaluation_detail_id
|
||||
select i.weight).Sum();
|
||||
|
||||
var current_item_weight = (from i in _repository.Context.eva_evaluation_achievement
|
||||
where i.id==id
|
||||
where i.id == id
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum - current_item_weight + model.weight > 100)
|
||||
@@ -185,61 +193,69 @@ namespace TodoAPI2.Models
|
||||
existingEntity.weight = model.weight;
|
||||
if (!string.IsNullOrEmpty(model.thefile))
|
||||
{
|
||||
if (model.thefile.StartsWith("Uploads"))
|
||||
{
|
||||
var thefileFileName = FileUtil.MoveTempUploadFileToActualPath(
|
||||
if (model.thefile.StartsWith("Uploads"))
|
||||
{
|
||||
var thefileFileName = FileUtil.MoveTempUploadFileToActualPath(
|
||||
model.thefile, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.thefile);
|
||||
existingEntity.thefile = thefileFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = model.thefile;
|
||||
}
|
||||
existingEntity.thefile = thefileFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = model.thefile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = null;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = null;
|
||||
}
|
||||
existingEntity.target_score1 = model.target_score1;
|
||||
existingEntity.target_score2 = model.target_score2;
|
||||
existingEntity.target_score3 = model.target_score3;
|
||||
existingEntity.target_score4 = model.target_score4;
|
||||
existingEntity.target_score5 = model.target_score5;
|
||||
|
||||
|
||||
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_achievementInputModel> model)
|
||||
public string UpdateMultiple(List<eva_evaluation_achievementInputModel> 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_detail_id = i.create_evaluation_detail_id;
|
||||
existingEntity.achievement = i.achievement;
|
||||
existingEntity.weight = i.weight;
|
||||
if (!string.IsNullOrEmpty(i.thefile))
|
||||
{
|
||||
if (i.thefile.StartsWith("Uploads"))
|
||||
{
|
||||
var thefileFileName = FileUtil.MoveTempUploadFileToActualPath(
|
||||
i.thefile, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.thefile);
|
||||
existingEntity.thefile = thefileFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = i.thefile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = null;
|
||||
}
|
||||
|
||||
existingEntity.create_evaluation_detail_id = i.create_evaluation_detail_id;
|
||||
existingEntity.achievement = i.achievement;
|
||||
existingEntity.weight = i.weight;
|
||||
if (!string.IsNullOrEmpty(i.thefile))
|
||||
{
|
||||
if (i.thefile.StartsWith("Uploads"))
|
||||
{
|
||||
var thefileFileName = FileUtil.MoveTempUploadFileToActualPath(
|
||||
i.thefile, FilePathConstant.DirType.FilesTestUpload, existingEntity.id, existingEntity.thefile);
|
||||
existingEntity.thefile = thefileFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = i.thefile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntity.thefile = null;
|
||||
}
|
||||
existingEntity.target_score1 = i.target_score1;
|
||||
existingEntity.target_score2 = i.target_score2;
|
||||
existingEntity.target_score3 = i.target_score3;
|
||||
existingEntity.target_score4 = i.target_score4;
|
||||
existingEntity.target_score5 = i.target_score5;
|
||||
|
||||
|
||||
_repository.UpdateWithoutCommit(i.id.Value, existingEntity);
|
||||
@@ -252,15 +268,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();
|
||||
}
|
||||
@@ -291,4 +307,6 @@ namespace TodoAPI2.Models
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user