private void Handle(IAcSession acSession, IGroupCreateIo input, bool isCommand) { var acDomain = _set._acDomain; var groupDic = _set._groupDic; var groupRepository = acDomain.RetrieveRequiredService <IRepository <Group, Guid> >(); if (!input.Id.HasValue) { throw new ValidationException("标识是必须的"); } var entity = Group.Create(input); lock (Locker) { GroupState group; if (acDomain.GroupSet.TryGetGroup(entity.Id, out group)) { throw new GeneralException("意外的重复标识"); } if (acDomain.GroupSet.Any(a => a.Name.Equals(input.Name, StringComparison.OrdinalIgnoreCase))) { throw new ValidationException("重复的工作组名"); } if (!groupDic.ContainsKey(entity.Id)) { groupDic.Add(entity.Id, GroupState.Create(entity)); } if (isCommand) { try { groupRepository.Add(entity); groupRepository.Context.Commit(); } catch { if (groupDic.ContainsKey(entity.Id)) { groupDic.Remove(entity.Id); } groupRepository.Context.Rollback(); throw; } } } if (isCommand) { acDomain.MessageDispatcher.DispatchMessage(new GroupAddedEvent(acSession, entity, input, isPrivate: true)); } }
public static Group Create(IGroupCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return(new Group(input.Id.Value) { CategoryCode = input.CategoryCode, Description = input.Description, IsEnabled = input.IsEnabled, Name = input.Name, ShortName = input.ShortName, SortCode = input.SortCode, TypeCode = input.TypeCode }); }
public static Group Create(IGroupCreateIo input) { Debug.Assert(input.Id != null, "input.Id != null"); return new Group { Id = input.Id.Value, CategoryCode = input.CategoryCode, Description = input.Description, IsEnabled = input.IsEnabled, Name = input.Name, ShortName = input.ShortName, SortCode = input.SortCode, TypeCode = input.TypeCode }; }