Esempio n. 1
0
        public WhenAddItemCommandIsHandled()
        {
            command = new AddItemCommand(Guid.NewGuid(), Guid.NewGuid());
            var commandHandler = new AddItemCommandHandler();

            cart = commandHandler.Handle(command);
        }
 private void AutoCompleteBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         AddItemCommand.Execute(null);
     }
 }
Esempio n. 3
0
        private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = (sender as Button).DataContext;

            LV_MinecraftItems.SelectedItem = item;
            AddItemCommand.Execute(item);
        }
Esempio n. 4
0
        public ucCraftingTree()
        {
            SortingTypes = new ObservableCollection <string> {
                "----------", "Name", "Category", "Required (High to Low)", "Required (Low to High)"
            };
            SortType = "----------";

            Categories = new ObservableCollection <string>
            {
                "All",
                "Building Blocks",
                "Decorations",
                "Redstone",
                "Transportation",
                "Miscellaneous",
                "Foodstuffs",
                "Brewing",
                "Combat"
            };
            CategoryIndex = 0;

            AddItemCommand    = new AddItemCommand(this);
            RemoveItemCommand = new RemoveItemCommand(this);

            InitializeComponent();
            LayoutRoot.DataContext = this;
        }
Esempio n. 5
0
 protected override void Initialize()
 {
     AddItemCommand.Initialize(this);
     ExtendElementsCommand.Initialize(this);
     NewFolder1.Command1.Initialize(this);
     base.Initialize();
 }
Esempio n. 6
0
        public async Task Execute_AddItemNoOtherItems()
        {
            // SETUP
            var item = new Item()
            {
                CategoryId = "catid",
                Name       = "Name1",
                Id         = Guid.NewGuid().ToString()
            };
            var fileStub = new FileStub(string.Empty);

            var rootFolderMock  = new Mock <IFolder> ();
            var itemsFolderMock = new Mock <IFolder> ();

            itemsFolderMock.Setup(ifm => ifm.GetFileAsync("items.data", default(CancellationToken))).ReturnsAsync(fileStub);
            rootFolderMock.Setup(rf => rf.CreateFolderAsync("items", CreationCollisionOption.OpenIfExists, default(CancellationToken))).ReturnsAsync(itemsFolderMock.Object);

            // ACTION
            var called  = false;
            var command = new AddItemCommand(rootFolderMock.Object);

            command.Added += (sender, e) => {
                called = true;
            };
            command.Execute(item);


            // ASSERT
            Assert.IsTrue(called);
            Assert.AreEqual(JsonConvert.SerializeObject(new List <Item> ()
            {
                item
            }), fileStub.WrittenContent);
        }
        public IActionResult AddItemFile(AddItemCommand cmd)
        {
            int a = 5;
            int b = a + 5;

            return(TryPush(cmd));
        }
Esempio n. 8
0
        private void Handle(AddItemCommand command)
        {
            var actor = GetCart(command.CartId);

            actor.Tell(command);
            pendingOperations.Add(command.Id, Sender);
        }
Esempio n. 9
0
        public async Task <ActionResult <int> > AddItem(int uId, int gId, int sId, AddItemCommand addItemCommand)
        {
            addItemCommand.Finalize(uId, gId, sId);

            var shoppingTripItemId = await _mediator.Send(addItemCommand);

            return(shoppingTripItemId);
        }
 public AdditionalDepositsPageViewModel(AccountModel accountModel, Mediator mediator)
 {
     GoToNextPage     = new RelayCommand <object>(arg => mediator.Invoke("OnGoToNextPage"));
     GoToPreviousPage = new RelayCommand <object>(arg => mediator.Invoke("OnGoToPreviousPage"));
     OnRemoveDeposit  = new RemoveItemCommand(accountModel.RemoveDeposit);
     OnAddDeposit     = new AddItemCommand(accountModel.AddDeposit);
     AccountModel     = accountModel;
 }
 public WithdrawalsPageViewModel(AccountModel accountModel, Mediator mediator)
 {
     GoToNextPage       = new RelayCommand <object>(arg => mediator.Invoke("OnGoToNextPage"));
     GoToPreviousPage   = new RelayCommand <object>(arg => mediator.Invoke("OnGoToPreviousPage"));
     OnRemoveWithdrawal = new RemoveItemCommand(accountModel.RemoveWithdrawal);
     OnAddWithdrawal    = new AddItemCommand(accountModel.AddWithdrawal);
     AccountModel       = accountModel;
 }
        public void should_have_error_when_GenreId_is_null()
        {
            var addItemCommand = new AddItemCommand {
                Price = new Money()
            };

            _validator.ShouldHaveValidationErrorFor(x => x.GenreId, addItemCommand);
        }
        private ICommand EnsureCommand(ECommandId idCommand)
        {
            NavigatorCommand command = null;

            lock (mSyncRoot)
            {
                command = mCachedCommands[(int)idCommand];
                if (command == null)
                {
                    switch (idCommand)
                    {
                    case ECommandId.NullRecord:
                        break;

                    case ECommandId.NextRecord:
                        command = new NextItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.PreviousRecord:
                        command = new PrevItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.FirstRecord:
                        command = new FirstItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.LastRecord:
                        command = new LastItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.GoToRecord:
                        break;

                    case ECommandId.AddRecord:
                        command = new AddItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.Save:
                        command = new SaveItemCommand(mViewDataManipulator);
                        break;

                    case ECommandId.DeleteRecord:
                        command = new DeleteItemCommand(mViewDataManipulator);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(idCommand), idCommand, null);
                    }

                    if (command != null)
                    {
                        mCachedCommands[(int)idCommand] = command;
                    }
                }
            }

            return(command);
        }
Esempio n. 14
0
        public async Task <IActionResult> AddItem(string id, [FromBody] AddItemCommand command, CancellationToken cancellationToken)
        {
            var basketAggregate = await _repository.Load(id, cancellationToken);

            basketAggregate.Apply(command);
            await _repository.Save(basketAggregate, cancellationToken);

            return(Ok());
        }
Esempio n. 15
0
 protected override void Initialize()
 {
     AddItemCommand.Initialize(this);
     AddPackageReferenceCommand.Initialize(this);
     BuildCurrentModelCommand.Initialize(this);
     ExtendElementsCommand.Initialize(this);
     NewFolder1.Command1.Initialize(this);
     base.Initialize();
 }
Esempio n. 16
0
        public void AddItem(AddItemCommand cmd)
        {
            ShoppingCartItem existingItem = items.Where(item => item.CreateSnapshot().ItemId == cmd.ItemId).FirstOrDefault();
            if (existingItem != null)
                items.Remove(existingItem);

            items.Add(ShoppingCartItem.Create(cmd.ItemId, cmd.Qty, cmd.Price, cmd.ItemCode, cmd.ItemName, cmd.UnitCode));
            this.totalAmountAfterDiscount = items.Sum(item => item.CreateSnapshot().AmountAfterDiscount);
        }
Esempio n. 17
0
        public async Task <IActionResult> AddItemAsync([FromBody] ItemDTO itemDTO)
        {
            var query  = new AddItemCommand(itemDTO);
            var result = await _meadiator.Send(query);

            return(result == true ? (IActionResult)Ok(result) : BadRequest(result));
            //var item = _mapper.Map<Item>(itemDTO);
            //var res = await _itemService.AddItemAysnc(item);
            //return res == true ? (IActionResult)Ok(res) : BadRequest(res);
        }
Esempio n. 18
0
 public ItemViewModel()
 {
     items                         = new ObservableCollection <ItemModel>();
     recommand_four                = new ObservableCollection <ItemModel>();
     recommandsList                = new ObservableCollection <ItemModel>();
     OpenItemCommandProperty       = new OpenItemCommand();
     OpenSearchItemCommandProperty = new OpenSearchItemCommand();
     AddItemCommandProperty        = new AddItemCommand();
     IsItemPopup                   = false;
 }
        public void should_have_error_when_GenreId_doesnt_exist()
        {
            _mediatorMock
            .Setup(x => x.Send(It.IsAny <GetGenreCommand>(), CancellationToken.None))
            .ReturnsAsync(() => null);

            var addItemCommand = new AddItemCommand {
                Price = new Money(), GenreId = Guid.NewGuid()
            };

            _validator.ShouldHaveValidationErrorFor(x => x.GenreId, addItemCommand);
        }
Esempio n. 20
0
        private async Task <int> HandleAsync(AddItemCommand command)
        {
            var item = new Item {
                Title = command.Title, IsDone = false, ListId = command.ListId
            };

            await this.context.Items.AddAsync(item);

            await this.context.SaveChangesAsync();

            return(item.Id);
        }
Esempio n. 21
0
        public async Task <IActionResult> AddItemInOrderItemList([FromBody] AddItemCommand command)
        {
            if (command == null)
            {
                return(await Respond(null, new List <Notification> {
                    new Notification("Order", "Parameters is invalid.")
                }));
            }

            var result = _orderCommandHandler.Handle(command);

            return(await Respond(result, _orderCommandHandler.Notifications));
        }
Esempio n. 22
0
        public void Handle(AddItemCommand command)
        {
            try
            {
                Thread.Sleep(new Random().Next(500, 4000));

                if (command.Id == Guid.Empty)
                {
                    throw new ArgumentNullException("command.Id");
                }
                if (string.IsNullOrEmpty(command.Name))
                {
                    throw new ArgumentNullException("command.Name");
                }

                Console.WriteLine("Got command: {0}, Id: {1}, Name: {2}", command.GetType().Name, command.Id, command.Name);

                using (var db = new MyReadStore())
                {
                    if (db.SomeItems.Where(x => x.Id == command.Id).Any())
                    {
                        throw new Exception("Item does already exists");
                    }
                    db.SomeItems.Add(new SomeItem()
                    {
                        Id = command.Id, Name = command.Name, IsActive = false
                    });
                    db.SaveChanges();
                }
                _publisher.Publish(new ItemAddedEvent()
                {
                    Id = command.Id, Name = command.Name
                });
                _publisher.Publish(new ClientNotification()
                {
                    Success  = true,
                    Message  = string.Format("The item '{0}' was added", command.Name),
                    ClientId = command.ClientId
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to execute command: {0}, Message: {1}", command.GetType().Name, ex.Message);
                _publisher.Publish(new ClientNotification()
                {
                    Success  = false,
                    Message  = string.Format("Could not add the item. Errormessage: ", ex.Message),
                    ClientId = command.ClientId
                });
            }
        }
Esempio n. 23
0
        public async Task <AddItemResponse> Handle(AddItemRequest request, CancellationToken cancellationToken)
        {
            var item    = this.mapper.Map <Item>(request);
            var command = new AddItemCommand()
            {
                Parameter = item
            };
            var itemFromDb = await this.commandExecutor.Execute(command);

            return(new AddItemResponse()
            {
                Data = this.mapper.Map <Domain.Models.Item>(itemFromDb)
            });
        }
        public BasketAggregateShould()
        {
            _addItemCommand = new AddItemCommand
            {
                Sku         = "12345",
                Description = "Product Description"
            };

            _updateItemCommand = new UpdateItemCommand
            {
                Sku      = _addItemCommand.Sku,
                Quantity = 2
            };
        }
Esempio n. 25
0
        private void Handle(AddItemCommand command)
        {
            if (!isInitialized)
            {
                Sender.Tell(new CommandFailed(command.Id, "Cart is not initialized!"));
                return;
            }

            if (!items.ContainsKey(command.ItemId))
            {
                items.Add(command.ItemId, 0);
            }
            items[command.ItemId] += command.Quantity;
            Sender.Tell(new ItemAddedEvent(command.Id, command.CartId, command.ItemId, command.Quantity));
        }
Esempio n. 26
0
        public void Apply(AddItemCommand command)
        {
            if (Items.Any(item => item.Sku == command.Sku))
            {
                return;
            }

            Items.Add(new ProductItem
            {
                Sku         = command.Sku,
                Description = command.Description
            });

            HasBeenUpdated = true;
        }
        public ActionResult Create(ItemViewModel itemViewModel)
        {
            if (ModelState.IsValid)
            {
                var addItemCommand = new AddItemCommand();
                Mapper.CreateMap<ItemViewModel, AddItemCommand>();
                Mapper.Map(itemViewModel, addItemCommand);

                CommandProcessor.Process<AddItemCommand, CommandResult>(addItemCommand, ModelState);
                if (!ModelState.IsValid)
                    return View();
                return this.RedirectToAction(c => c.Index(null, null));
            }

            return View();
        }
Esempio n. 28
0
        private void DeleteItemCommandExecute()
        {
            DeleteItemRequest request = new DeleteItemRequest {
                Item = SelectedItem
            };

            DeleteItemRequest.Raise(request, returned =>
            {
                if (!request.Confirmed)
                {
                    return;
                }
                Items.Remove(SelectedItem);
            });

            AddItemCommand.RaiseCanExecuteChanged();
        }
Esempio n. 29
0
        public MainWindowViewModel()
        {
            this.WhenAnyValue(x => x.ItemCount).Subscribe(ResizeItems);
            RecreateCommand = ReactiveCommand.Create();
            RecreateCommand.Subscribe(_ => Recreate());

            AddItemCommand = ReactiveCommand.Create();
            AddItemCommand.Subscribe(_ => AddItem());

            RemoveItemCommand = ReactiveCommand.Create();
            RemoveItemCommand.Subscribe(_ => Remove());

            SelectFirstCommand = ReactiveCommand.Create();
            SelectFirstCommand.Subscribe(_ => SelectItem(0));

            SelectLastCommand = ReactiveCommand.Create();
            SelectLastCommand.Subscribe(_ => SelectItem(Items.Count - 1));
        }
Esempio n. 30
0
        private IEnumerable <Item> ParseAddItemCommand(AddItemCommand commandXml)
        {
            List <Item>         objList = new List <Item>();
            string              str1    = commandXml.AddedItemData.DatabaseName;
            string              str2    = commandXml.AddedItemData.Name;
            string              str3    = commandXml.AddedItemData.ID;
            string              str4    = commandXml.AddedItemData.BranchId;
            string              str5    = commandXml.AddedItemData.ParentId;
            string              str6    = commandXml.AddedItemData.TemplateId;
            IEnumerable <Field> first   = this.ParseFields(commandXml.AddedItemData.SharedFields)
                                          .Select <KeyValuePair <string, string>, Field>((Func <KeyValuePair <string, string>, Field>)(f => new Field()
            {
                FieldType = FieldType.Shared,
                Id        = f.Key,
                Value     = f.Value
            }));

            foreach (var xpathSelectElement in commandXml.AddedItemData.Versions)
            {
                string str7 = xpathSelectElement.Version;
                string str8 = xpathSelectElement.Language;
                IEnumerable <Field> second = this.ParseFields(xpathSelectElement.Fields)
                                             .Select <KeyValuePair <string, string>, Field>((Func <KeyValuePair <string, string>, Field>)(f => new Field()
                {
                    FieldType = FieldType.Unknown,
                    Id        = f.Key,
                    Value     = f.Value
                }));
                objList.Add(new Item()
                {
                    Database   = str1,
                    Name       = str2,
                    Id         = str3,
                    MasterId   = str4,
                    ParentId   = str5,
                    TemplateId = str6,
                    Language   = str8,
                    Version    = str7,
                    Fields     = first.Union <Field>(second)
                });
            }

            return((IEnumerable <Item>)objList);
        }
Esempio n. 31
0
 public Infrastructure Create(ModelEntities entity, string function)
 {
     if (function == "item")
     {
         ItemViews         _view             = new ItemViews();
         SelectionCommand  selectionCommand  = new SelectionCommand(_view);
         UpdateItemCommand updateItemCommand = new UpdateItemCommand(_view);
         AddItemCommand    addItemCommand    = new AddItemCommand(_view);
         ViewModel         _viewModel        = new ViewModel(entity, selectionCommand.Command, updateItemCommand.Command, addItemCommand.Command);
         selectionCommand.ViewModel  = _viewModel;
         updateItemCommand.ViewModel = _viewModel;
         addItemCommand.ViewModel    = _viewModel;
         return(new Infrastructure(_view, _viewModel, entity));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 32
0
        private void almImportClick(object sender, RoutedEventArgs e)
        {
            var innovator = getInnovator();

            if (_openAmlDialog.ShowDialog() == true && innovator != null)
            {
                var dom = new XmlDocument();
                dom.Load(_openAmlDialog.FileName);

                var item = innovator.newItem();
                item.loadAML(dom.OuterXml);

                string importError = EnsureSingleItem(null, "add", ref item);
                if (string.IsNullOrEmpty(importError))
                {
                    string itemTypeName = item.getType();
                    var    itemType     = _project.ItemTypes.FirstOrDefault(it => it.Name == itemTypeName);
                    if (itemType != null)
                    {
                        var addItemCommand = new AddItemCommand(_project, itemType, 0, 0);
                        _project.PerformCommand(addItemCommand);
                        Item importedItem = addItemCommand.NewItem;

                        foreach (var property in importedItem.Properties)
                        {
                            property.Value = item.getProperty(property.Name);
                        }

                        _allItemControls[importedItem].Item = importedItem;                         // update after properties are refreshed
                    }
                    else
                    {
                        MessageBox.Show($"There are no \"{itemTypeName}\" type found.", "Impossible to import", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show(importError, "Impossible to import", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }