public static IList<IdentifyingCodeDetailSearchDTO> GetIdentifyingCodeDetailById(Guid identifyingCodeId, string moduleName) { if (Guid.Empty.Equals(identifyingCodeId) || string.IsNullOrEmpty(moduleName)) { return null; } var identifyingCode = new IdentifyingCodeInfo() { IdentifyingCodeId = identifyingCodeId, ModuleName = moduleName }; using (var context = new HotelDbContext()) { IIdentifyingCodeRepository repository = new IdentifyingCodeRepository(context); //改造方向:依赖注入,彻底去除对Infrastructure层的依赖 return repository.GetIdentifyingCodeDetailById(identifyingCode); } }
public static bool AddIdentifyingCode(IdentifyingCodeInfo code) { if (code != null) { var addResult = false; code.IdentifyingCode = Utils.Number(12); using (var context = new HotelDbContext()) { addResult = new IdentifyingCodeRepository(context).AddIdentifyingCode(code); } // 如果IdentifyingCode在数据库中存在,则递归执行此方法重新获取编号 if (!addResult) { AddIdentifyingCode(code); } else { return true; } } return false; }