ปรับปรุงสิทธิการมองเห็นต่างๆ

This commit is contained in:
Nakorn Rientrakrunchai
2020-03-01 17:17:43 +07:00
parent c65c179e85
commit f8f46bb346
29 changed files with 448 additions and 696 deletions

View File

@@ -20,14 +20,14 @@ namespace TodoAPI2.Models
public class eva_evaluation_achievement_process2Service : Ieva_evaluation_achievement_process2Service
{
private IBaseRepository2<eva_evaluation_achievementEntity, int> _repository;
private IMyDatabase db;
private Iexternal_linkageService ext;
private IMyDatabase db;
private Iexternal_linkageService ext;
public eva_evaluation_achievement_process2Service(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_achievement_process2ViewModel>>(entities);
}
#endregion
#region Public Functions
@@ -77,12 +77,12 @@ namespace TodoAPI2.Models
public List<eva_evaluation_achievement_process2ViewModel> GetListBycreate_evaluation_detail_id(int? create_evaluation_detail_id)
{
var model = new eva_evaluation_achievement_process2SearchModel();
var model = new eva_evaluation_achievement_process2SearchModel();
model.create_evaluation_detail_id = create_evaluation_detail_id;
return GetListBySearch(model);
}
public List<eva_evaluation_achievement_process2ViewModel> GetListBySearch(eva_evaluation_achievement_process2SearchModel model)
public List<eva_evaluation_achievement_process2ViewModel> GetListBySearch(eva_evaluation_achievement_process2SearchModel model)
{
var data = (
from m_eva_evaluation_achievement_process2 in _repository.Context.eva_evaluation_achievement
@@ -92,7 +92,7 @@ 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_process2.id == model.id || !model.id.HasValue)
&& (m_eva_evaluation_achievement_process2.create_evaluation_detail_id == model.create_evaluation_detail_id || !model.create_evaluation_detail_id.HasValue)
@@ -135,10 +135,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;
}
@@ -160,7 +160,7 @@ namespace TodoAPI2.Models
}
var inserted = _repository.Insert(entity);
return Get(inserted.id);
}
@@ -174,21 +174,21 @@ 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.score = model.score;
existingEntity.score2 = model.score2;
@@ -204,38 +204,48 @@ namespace TodoAPI2.Models
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_achievement_process2InputModel> model)
public string UpdateMultiple(List<eva_evaluation_achievement_process2InputModel> 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);
var current_detail = (from k in _repository.Context.eva_create_evaluation_detail
where k.id == existingEntity.create_evaluation_detail_id
select k).FirstOrDefault();
if (current_detail.status_supervisor == "Y")
{
throw new Exception("ผู้ประเมินสูงสุด ส่งแบบประเมินไปแล้ว บันทึกไม่ได้");
}
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.score = i.score;
existingEntity.score2 = i.score2;
@@ -257,15 +267,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();
}