Example #1
0
 public static Menu Create(IMenuCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return(new Menu(input.Id.Value)
     {
         AppSystemId = input.AppSystemId,
         Name = input.Name,
         Icon = input.Icon,
         Description = input.Description,
         ParentId = input.ParentId,
         SortCode = input.SortCode,
         Url = input.Url
     });
 }
Example #2
0
 public static Menu Create(IMenuCreateIo input)
 {
     Debug.Assert(input.Id != null, "input.Id != null");
     return new Menu
     {
         AppSystemId = input.AppSystemId,
         Id = input.Id.Value,
         Name = input.Name,
         Icon = input.Icon,
         Description = input.Description,
         ParentId = input.ParentId,
         SortCode = input.SortCode,
         Url = input.Url
     };
 }
Example #3
0
            private void Handle(IAcSession acSession, IMenuCreateIo input, bool isCommand)
            {
                var acDomain       = _set._acDomain;
                var menuById       = _set._menuById;
                var menuRepository = acDomain.RetrieveRequiredService <IRepository <Menu, Guid> >();

                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                MenuState menu;

                if (acDomain.MenuSet.TryGetMenu(input.Id.Value, out menu))
                {
                    throw new ValidationException("给定标识的实体已经存在" + input.Id);
                }
                if (input.ParentId.HasValue)
                {
                    MenuState parentMenu;
                    if (!acDomain.MenuSet.TryGetMenu(input.ParentId.Value, out parentMenu))
                    {
                        throw new NotExistException("标识为" + input.ParentId.Value + "的父菜单不存在");
                    }
                    if (input.AppSystemId != parentMenu.AppSystemId)
                    {
                        throw new ValidationException("非法的数据,子菜单的应用系统必须和父菜单一致");
                    }
                }

                var entity = Menu.Create(input);

                lock (Locker)
                {
                    if (acDomain.MenuSet.TryGetMenu(input.Id.Value, out menu))
                    {
                        throw new ValidationException("给定标识的实体已经存在" + input.Id);
                    }
                    if (input.ParentId.HasValue)
                    {
                        MenuState parentMenu;
                        if (!acDomain.MenuSet.TryGetMenu(input.ParentId.Value, out parentMenu))
                        {
                            throw new NotExistException("标识为" + input.ParentId.Value + "的父菜单不存在");
                        }
                    }
                    var menuState = MenuState.Create(acDomain, entity);
                    if (!menuById.ContainsKey(entity.Id))
                    {
                        menuById.Add(entity.Id, menuState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            menuRepository.Add(entity);
                            menuRepository.Context.Commit();
                        }
                        catch
                        {
                            if (menuById.ContainsKey(entity.Id))
                            {
                                menuById.Remove(entity.Id);
                            }
                            menuRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new MenuAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }