我有两个目标:
LabTest
LabTestDetails
Where a LabTest
object can have zero or many LabTestDetails
objects.
I need to implement the following business rule:-
用户如果被分配到一个或多个《实验室试验条约》物体,就不应编辑。
(一) 采用一种名为“标签”的助手方法,在“拉贝”物体上(如果把“拉比”物体转让给任何“拉比”物体): ——
public partial class LabTest
{
public bool IsAlreadyAssigned(int id)
{
return (LabTestDetailss.Any(r2 => r2.LabTestID == id));
}}
然后,我增加了对<代码>的如下检查: Get & Post 宣传行动方法:-
public ActionResult Edit(int id)
{
LabTest c = repository.GetLabTest (id);
if ((c == null) || (c.IsAlreadyAssigned (id)))
{
return View("Error");
}
return View(c);
}
[HttpPost]
public ActionResult Edit(int id, FormCollection colletion)
{
LabTest c = repository.GetLabTest (id);
if ((c == null) || (c.IsAlreadyAssigned (id))) // *******
{
return View("Error");
}
try
{
if (TryUpdateModel(c))
{
elearningrepository.Save();
return RedirectToAction("Details", new { id = c.LabTestID });
}
}
以上可能会对大多数案件进行罚款,但如果<代码> 试验编码>物体在<代码>后被另一用户指派到实验室试验详细物上(c=无效) 劳动标记((d)) 核对有关上述代码(>>>*<>>>)的员额行动方法,那么我的业务逻辑就会破碎。
so is there a way to implement my action methods so that it will always prevent editing a LabTest object if it has been assigned to a LabTestdetail object .
不丹