正在使用工作单元,但我不明白将提交放在存储库类或控制器中的哪里?

问题描述 投票:0回答:1
[HttpPost]
public async Task<ActionResult> EmployeeEdit(EmployeeViewModel model)
{
    var emp = await _unitOfWork.Employee.FindById(model.EmployeeId);
    if (emp == null)
    {
        return Json(new { success = false, error = "Employee not found." });
    }  
    if(model.ProfilePictureImg.Length > 0)
    {
        var docResponse = _unitOfWork.DocumentImage.UploadFile(model.ProfilePictureImg,     _appSettings.DocumentImagePath);
        model.ProfilePicture = docResponse.VirtualPath;
    }
    var updateResult = await _unitOfWork.Employee.UpdateEmployee(model);
    if(updateResult == true)
    {
        await _unitOfWork.Commit();

    }
    return Json(new { success = updateResult });
}

`在上面的代码中,我应该在上面的 UpdateEmployee 或控制器中的哪里使用 commit() ,我是否需要在提交之前检查 updateResult 或者我必须为工作单元类做一些事情来检查自身?

我想知道在工作单元中执行此操作的标准方法是什么?`

c# .net repository-pattern unit-of-work
1个回答
0
投票

我认为它应该在UpdateEmployee之外,因为有时你会想在一次Commit中更新多个实体对象。

© www.soinside.com 2019 - 2024. All rights reserved.