Example #1
0
 public static Button Create(IButtonCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return(new Button(input.Id.Value)
     {
         Code = input.Code,
         Name = input.Name,
         Icon = input.Icon,
         Description = input.Description,
         CategoryCode = input.CategoryCode,
         IsEnabled = input.IsEnabled,
         SortCode = input.SortCode
     });
 }
Example #2
0
 public static Button Create(IButtonCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return new Button
     {
         Id = input.Id.Value,
         Code = input.Code,
         Name = input.Name,
         Icon = input.Icon,
         Description = input.Description,
         CategoryCode = input.CategoryCode,
         IsEnabled = input.IsEnabled,
         SortCode = input.SortCode
     };
 }
Example #3
0
            private void Handle(IAcSession acSession, IButtonCreateIo input, bool isCommand)
            {
                var acDomain         = _set._acDomain;
                var dicById          = _set._dicById;
                var dicByCode        = _set._dicByCode;
                var buttonRepository = acDomain.RetrieveRequiredService <IRepository <Button> >();

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

                lock (MessageLocker)
                {
                    if (acDomain.ButtonSet.ContainsButton(input.Id.Value))
                    {
                        throw new AnycmdException("给定标识的记录已经存在" + input.Id);
                    }
                    if (acDomain.ButtonSet.ContainsButton(input.Code))
                    {
                        throw new ValidationException("重复的按钮编码");
                    }

                    entity = Button.Create(input);

                    var buttonState = ButtonState.Create(entity);
                    if (!dicById.ContainsKey(entity.Id))
                    {
                        dicById.Add(entity.Id, buttonState);
                    }
                    if (!dicByCode.ContainsKey(entity.Code))
                    {
                        dicByCode.Add(entity.Code, buttonState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            buttonRepository.Add(entity);
                            buttonRepository.Context.Commit();
                        }
                        catch
                        {
                            if (dicById.ContainsKey(entity.Id))
                            {
                                dicById.Remove(entity.Id);
                            }
                            if (dicByCode.ContainsKey(entity.Code))
                            {
                                dicByCode.Remove(entity.Code);
                            }
                            buttonRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new ButtonAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }