รวม code แก้ issue #1
This commit is contained in:
@@ -142,6 +142,14 @@ namespace TodoAPI2.Models
|
||||
var entity = GetEntity(model);
|
||||
entity.id = GetNewPrimaryKey();
|
||||
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_achievement
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum + model.weight > 100)
|
||||
{
|
||||
throw new Exception("ไม่สามารถบันทึกค่าน้ำหนักในส่วนผลสัมฤทธิ์ของงาน ได้เกิน 100");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.thefile))
|
||||
{
|
||||
//Move file from temp to physical
|
||||
@@ -157,6 +165,18 @@ namespace TodoAPI2.Models
|
||||
|
||||
public eva_evaluation_achievementViewModel Update(int id, eva_evaluation_achievementInputModel model)
|
||||
{
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_achievement
|
||||
select i.weight).Sum();
|
||||
|
||||
var current_item_weight = (from i in _repository.Context.eva_evaluation_achievement
|
||||
where i.id==id
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum - current_item_weight + model.weight > 100)
|
||||
{
|
||||
throw new Exception("ไม่สามารถบันทึกค่าน้ำหนักในส่วนผลสัมฤทธิ์ของงาน ได้เกิน 100");
|
||||
}
|
||||
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
|
||||
@@ -140,7 +140,13 @@ namespace TodoAPI2.Models
|
||||
var entity = GetEntity(model);
|
||||
entity.id = GetNewPrimaryKey();
|
||||
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_behavior
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum + model.weight > 100)
|
||||
{
|
||||
throw new Exception("ไม่สามารถบันทึกค่าน้ำหนักในส่วนผลสัมฤทธิ์ของงาน ได้เกิน 100");
|
||||
}
|
||||
|
||||
var inserted = _repository.Insert(entity);
|
||||
|
||||
@@ -149,6 +155,18 @@ namespace TodoAPI2.Models
|
||||
|
||||
public eva_evaluation_behaviorViewModel Update(int id, eva_evaluation_behaviorInputModel model)
|
||||
{
|
||||
var current_sum = (from i in _repository.Context.eva_evaluation_behavior
|
||||
select i.weight).Sum();
|
||||
|
||||
var current_item_weight = (from i in _repository.Context.eva_evaluation_behavior
|
||||
where i.id == id
|
||||
select i.weight).Sum();
|
||||
|
||||
if (current_sum - current_item_weight + model.weight > 100)
|
||||
{
|
||||
throw new Exception("ไม่สามารถบันทึกค่าน้ำหนักในส่วนพฤติกรรมการปฏิบัติงาน ได้เกิน 100");
|
||||
}
|
||||
|
||||
var existingEntity = _repository.Get(id);
|
||||
if (existingEntity != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user