public InfoDicItemAddedEvent(IAcSession acSession, InfoDicItemBase source, IInfoDicItemCreateIo output)
     : base(acSession, source)
 {
     if (output == null)
     {
         throw new System.ArgumentNullException("output");
     }
     this.Output = output;
 }
Beispiel #2
0
 public InfoDicItemAddedEvent(IAcSession acSession, InfoDicItemBase source, IInfoDicItemCreateIo output)
     : base(acSession, source)
 {
     if (output == null)
     {
         throw new System.ArgumentNullException("output");
     }
     this.Output = output;
 }
Beispiel #3
0
 public static InfoDicItem Create(IInfoDicItemCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return(new InfoDicItem(input.Id.Value)
     {
         Code = input.Code,
         Description = input.Description,
         InfoDicId = input.InfoDicId,
         IsEnabled = input.IsEnabled,
         Level = input.Level,
         Name = input.Name,
         SortCode = input.SortCode
     });
 }
Beispiel #4
0
 public static InfoDicItem Create(IInfoDicItemCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return new InfoDicItem
     {
         Code = input.Code,
         Description = input.Description,
         Id = input.Id.Value,
         InfoDicId = input.InfoDicId,
         IsEnabled = input.IsEnabled,
         Level = input.Level,
         Name = input.Name,
         SortCode = input.SortCode
     };
 }
Beispiel #5
0
 internal InfoDicItemAddedEvent(IAcSession acSession, InfoDicItemBase source, IInfoDicItemCreateIo input, bool isPrivate)
     : this(acSession, source, input)
 {
     this.IsPrivate = isPrivate;
 }
Beispiel #6
0
            private void Handle(IAcSession acSession, IInfoDicItemCreateIo input, bool isCommand)
            {
                var acDomain              = _set._acDomain;
                var infoDicItemDic        = _set._infoDicItemDic;
                var infoDicItemByDic      = _set._infoDicItemByDic;
                var infoDicItemRepository = acDomain.RetrieveRequiredService <IRepository <InfoDicItem, Guid> >();

                if (string.IsNullOrEmpty(input.Code))
                {
                    throw new ValidationException("编码不能为空");
                }
                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                InfoDicState infoDic;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDic(input.InfoDicId, out infoDic))
                {
                    throw new ValidationException("意外的信息字典标识");
                }
                InfoDicItemState infoDicItem;

                if (acDomain.NodeHost.InfoDics.TryGetInfoDicItem(input.Id.Value, out infoDicItem))
                {
                    throw new ValidationException("给定的标识标识的记录已经存在");
                }
                if (acDomain.NodeHost.InfoDics.TryGetInfoDicItem(infoDic, input.Code, out infoDicItem))
                {
                    throw new ValidationException("重复的编码");
                }

                var entity = InfoDicItem.Create(input);

                lock (Locker)
                {
                    var state = InfoDicItemState.Create(entity);
                    if (!infoDicItemDic.ContainsKey(entity.Id))
                    {
                        infoDicItemDic.Add(entity.Id, state);
                    }
                    if (!infoDicItemByDic.ContainsKey(infoDic))
                    {
                        infoDicItemByDic.Add(infoDic, new Dictionary <dicItemCode, InfoDicItemState>(StringComparer.OrdinalIgnoreCase));
                    }
                    if (!infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                    {
                        infoDicItemByDic[infoDic].Add(entity.Code, state);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            infoDicItemRepository.Add(entity);
                            infoDicItemRepository.Context.Commit();
                        }
                        catch
                        {
                            if (infoDicItemDic.ContainsKey(entity.Id))
                            {
                                infoDicItemDic.Remove(entity.Id);
                            }
                            if (infoDicItemByDic.ContainsKey(infoDic) && infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                            {
                                infoDicItemByDic[infoDic].Remove(entity.Code);
                            }
                            infoDicItemRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new InfoDicItemAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }
 public static void AddInfoDicItem(this IAcDomain acDomain, IAcSession acSession, IInfoDicItemCreateIo input)
 {
     acDomain.Handle(new AddInfoDicItemCommand(acSession, input));
 }
 internal InfoDicItemAddedEvent(IAcSession acSession, InfoDicItemBase source, IInfoDicItemCreateIo input, bool isPrivate)
     : this(acSession, source, input)
 {
     this.IsPrivate = isPrivate;
 }
 public static void AddInfoDicItem(this IAcDomain acDomain, IAcSession acSession, IInfoDicItemCreateIo input)
 {
     acDomain.Handle(new AddInfoDicItemCommand(acSession, input));
 }