รวม code แก้ issue #1

This commit is contained in:
Nakorn Rientrakrunchai
2020-02-21 00:16:37 +07:00
parent e4f3417bef
commit d9ca4b0aed
8 changed files with 106 additions and 12 deletions

View File

@@ -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)
{