public static SsdRole Create(ISsdRoleCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return(new SsdRole(input.Id.Value) { SsdSetId = input.SsdSetId, RoleId = input.RoleId }); }
public static SsdRole Create(ISsdRoleCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return new SsdRole { Id = input.Id.Value, SsdSetId = input.SsdSetId, RoleId = input.RoleId }; }
private void Handle(IAcSession acSession, ISsdRoleCreateIo input, bool isCommand) { var acDomain = _set._acDomain; var ssdRoleBySet = _set._ssdRoleBySet; var ssdRoleById = _set._ssdRoleById; var ssdRoleRepository = acDomain.RetrieveRequiredService <IRepository <SsdRole, Guid> >(); if (!input.Id.HasValue) { throw new ValidationException("标识是必须的"); } if (ssdRoleById.Any(a => a.Key == input.Id.Value || (a.Value.RoleId == input.RoleId && a.Value.SsdSetId == input.SsdSetId))) { throw new ValidationException("重复的记录"); } SsdSetState ssdSet; if (!acDomain.SsdSetSet.TryGetSsdSet(input.SsdSetId, out ssdSet)) { throw new ValidationException("意外的静态责任分离角色集标识" + input.SsdSetId); } var entity = SsdRole.Create(input); lock (Locker) { if (ssdRoleById.Any(a => a.Key == input.Id.Value || (a.Value.RoleId == input.RoleId && a.Value.SsdSetId == input.SsdSetId))) { throw new ValidationException("重复的记录"); } if (!acDomain.SsdSetSet.TryGetSsdSet(input.SsdSetId, out ssdSet)) { throw new ValidationException("意外的静态责任分离角色集标识" + input.SsdSetId); } var state = SsdRoleState.Create(entity); if (!ssdRoleById.ContainsKey(entity.Id)) { ssdRoleById.Add(entity.Id, state); } if (!ssdRoleBySet.ContainsKey(ssdSet)) { ssdRoleBySet.Add(ssdSet, new List <SsdRoleState>()); } ssdRoleBySet[ssdSet].Add(state); if (isCommand) { try { ssdRoleRepository.Add(entity); ssdRoleRepository.Context.Commit(); } catch { if (ssdRoleById.ContainsKey(entity.Id)) { ssdRoleById.Remove(entity.Id); } ssdRoleBySet[ssdSet].Remove(state); ssdRoleRepository.Context.Rollback(); throw; } } } if (isCommand) { acDomain.MessageDispatcher.DispatchMessage(new SsdRoleAddedEvent(acSession, entity, input, isPrivate: true)); } }