public static DsdRole Create(IDsdRoleCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return(new DsdRole(input.Id.Value) { RoleId = input.RoleId, DsdSetId = input.DsdSetId }); }
public static DsdRole Create(IDsdRoleCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return new DsdRole { Id = input.Id.Value, RoleId = input.RoleId, DsdSetId = input.DsdSetId }; }
private void Handle(IAcSession acSession, IDsdRoleCreateIo input, bool isCommand) { var acDomain = _set._acDomain; var dsdRoleBySet = _set._dsdRoleBySet; var dsdRoleById = _set._dsdRoleById; var dsdRoleRepository = acDomain.RetrieveRequiredService <IRepository <DsdRole> >(); if (!input.Id.HasValue) { throw new ValidationException("标识是必须的"); } if (dsdRoleById.Any(a => a.Key == input.Id.Value || (a.Value.RoleId == input.RoleId && a.Value.DsdSetId == input.DsdSetId))) { throw new ValidationException("重复的记录"); } DsdSetState dsdSet; if (!acDomain.DsdSetSet.TryGetDsdSet(input.DsdSetId, out dsdSet)) { throw new ValidationException("意外的动态责任分离角色集标识" + input.DsdSetId); } var entity = DsdRole.Create(input); lock (Locker) { if (dsdRoleById.Any(a => a.Key == input.Id.Value || (a.Value.RoleId == input.RoleId && a.Value.DsdSetId == input.DsdSetId))) { throw new ValidationException("重复的记录"); } if (!acDomain.DsdSetSet.TryGetDsdSet(input.DsdSetId, out dsdSet)) { throw new ValidationException("意外的动态责任分离角色集标识" + input.DsdSetId); } var state = DsdRoleState.Create(entity); if (!dsdRoleById.ContainsKey(entity.Id)) { dsdRoleById.Add(entity.Id, state); } if (!dsdRoleBySet.ContainsKey(dsdSet)) { dsdRoleBySet.Add(dsdSet, new List <DsdRoleState>()); } dsdRoleBySet[dsdSet].Add(state); if (isCommand) { try { dsdRoleRepository.Add(entity); dsdRoleRepository.Context.Commit(); } catch { if (dsdRoleById.ContainsKey(entity.Id)) { dsdRoleById.Remove(entity.Id); } dsdRoleBySet[dsdSet].Remove(state); dsdRoleRepository.Context.Rollback(); throw; } } } if (isCommand) { acDomain.MessageDispatcher.DispatchMessage(new DsdRoleAddedEvent(acSession, entity, input, isPrivate: true)); } }