public void Delete(DeleteItemCommand message)
        {
            var item = new T();

            item.Id = message.Id;
            _repository.Save(item, -1);
        }
Esempio n. 2
0
 public ItemDetailVM()
 {
     DeleteItemCommand = new DeleteItemCommand(this);
     UpdateItemCommand = new UpdateItemCommand(this);
     ClosePopUpCommand = new ClosePopUpCommand(this);
     Item = new Item();
 }
Esempio n. 3
0
        public async Task <IActionResult> DeleteItem([FromRoute(Name = "itemId")] int itemId)
        {
            var command = new DeleteItemCommand(new Domain.StoreItems.Models.ItemId(itemId));
            await commandDispatcher.DispatchAsync(command, default);

            return(Ok());
        }
Esempio n. 4
0
        public async Task <Unit> Handle(DeleteItemCommand request, CancellationToken cancellationToken)
        {
            _unitOfWork.ItemRepo.Delete(request.Id);
            await _unitOfWork.SaveAsync();

            return(Unit.Value);
        }
        private void InitializeCommands()
        {
            AddItemCommand = new DelegateCommand <ItemModel>((item) =>
            {
                Items.Add(new ItemViewModel(item));
                DeleteItemCommand.RaiseCanExecuteChanged();
            });

            DeleteItemCommand = new DelegateCommand <int>((int index) =>
            {
                Items.RemoveAt(index);
            },
                                                          (int index) =>
            {
                if (index == -1)
                {
                    return(false);
                }

                return(Items.Count > 0);
            });

            GoHomeCommand = new DelegateCommand(() =>
            {
                NavigationService.Navigate(UniversalApp.Current.DefaultPage);
            });
        }
        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. 7
0
        public override void ReverseInit(object returnedData)
        {
            base.ReverseInit(returnedData);

            if (returnedData is ProductQuotationModel)
            {
                DeleteItemCommand.Execute(returnedData);
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> DeleteItemAsync(int id)
        {
            var query  = new DeleteItemCommand(id);
            var result = await _meadiator.Send(query);

            return(result == true ? (IActionResult)Ok(result) : BadRequest(result));
            //var res = await _itemService.DeleteItemAysnc(id);
            //return res == true ? (IActionResult)Ok(res) : BadRequest(res);
        }
Esempio n. 9
0
        private async Task <bool> HandleAsync(DeleteItemCommand command)
        {
            var item = await this.context.Items.FindAsync(command.ItemId);

            this.context.Items.Remove(item);
            var count = await this.context.SaveChangesAsync();

            return(count >= 0);
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            var request = new DeleteItemCommand {
                Id = id
            };
            await _mediator.Send(request);

            return(NoContent());
        }
        public async Task <ActionResult> Delete(int id)
        {
            var deleteItemCommand = new DeleteItemCommand()
            {
                ItemId = id
            };
            await _mediator.Send(deleteItemCommand);

            return(NoContent());
        }
Esempio n. 12
0
 private bool CanDeleteItem(object parameter)
 {
     if (DeleteItemCommand != null)
     {
         return(CurrentItemIndex > 0 &&
                DeleteItemCommand.CanExecute(parameter));
     }
     return(CurrentItemIndex > 0 &&
            IsCollection(ItemsSource));
 }
 public IHttpActionResult Delete(int id)
 {
     return(ExecuteCommand(() => {
         var command = new DeleteItemCommand()
         {
             Id = id
         };
         _deleteCommandHandler.Handle(command);
     }));
 }
Esempio n. 14
0
 public DrugsManagementViewModel(AdminShellViewModel shellViewModel)
 {
     drugsManagementM         = new DrugsManagementModel();
     Items                    = new ObservableCollection <Drug>(drugsManagementM.Drugs);
     Items.CollectionChanged += DrugsChanged;
     this.containingShellVm   = shellViewModel;
     EditCommand              = new EditingItemCommand(this);
     DeleteCommand            = new DeleteItemCommand(this);
     SearchCommand            = new SearchItemCommand(this);
     ScreenReplacementCommand = new ScreenReplacementCommand(this);
 }
        public void ShouldReturnFalseIfNoItemFound(DeleteItemCommand sut, Item item, ID parentId)
        {
            // arrange
            sut.Initialize(item, parentId);

            // act
            var result = (bool)ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            result.Should().BeFalse();
        }
 public PhysiciansManagementViewModel(AdminShellViewModel shellViewModel)
 {
     physiciansManagementM = new PhysiciansManagementModel();
     Items = new ObservableCollection <Physician>(physiciansManagementM.Physicians);
     Items.CollectionChanged += PhysiciansChanged;
     this.containingShellVm   = shellViewModel;
     EditCommand              = new EditingItemCommand(this);
     DeleteCommand            = new DeleteItemCommand(this);
     SearchCommand            = new SearchItemCommand(this);
     ScreenReplacementCommand = new ScreenReplacementCommand(this);
 }
 public ConsumptionOfDrugsViewModel(PhysicianShellViewModel containingVm, string patientId)
 {
     medicalFileModel         = new MedicalFileModel(patientId);
     this.containingVm        = containingVm;
     DrugsPreviouslyTaken     = new ObservableCollection <Recept>(medicalFileModel.AllRecepts.Where(x => x.TreatmentEndDate < DateTime.Now));
     DrugsTake                = new ObservableCollection <Recept>(medicalFileModel.AllRecepts.Where(x => x.TreatmentEndDate >= DateTime.Now));
     ListDisplay              = new ObservableCollection <Recept>(DrugsTake);
     BackCommand              = new BackCommand(this);
     ChangeListDisplayCommand = new ChangeListDisplayCommand(this);
     RemoveFromDb             = new DeleteItemCommand(this);
 }
Esempio n. 18
0
        public async Task <ActionResult> DeleteConfirmed([Bind("Id")] string id)
        {
            var command = new DeleteItemCommand {
                Id = new Guid(id)
            };

            await _messaging.SendCommand(command);

            TempData["message"] = "Item deleted";

            return(RedirectToRoute("ListItems", new { lastCommandId = command.CommandId }));
        }
 public AddDrugViewModel(AdminShellViewModel containingVm)
 {
     addDrugM                = new AddDrugModel();
     this.containingVm       = containingVm;
     UpdateDbCommand         = new AddToDbCommand(this);
     IsNewDrug               = true;
     BackCommand             = new BackCommand(this);
     IngredientToAdd         = new ActiveIngredient();
     Ingredients             = new ObservableCollection <ActiveIngredient>();
     AddIngredientCommand    = new AddIngredientToDrugCommand(this);
     DeleteIngredientCommand = new DeleteItemCommand(this);
     FileDialogCommand       = new OpenFileDialogCommand(this);
 }
Esempio n. 20
0
        public void Execute_DeleteItemCommand_WithPosition_ShouldRemoveItemFromItemsList()
        {
            var documentItems = new List <DocumentItem>
            {
                new DocumentItem(new TestParagraph()),
                new DocumentItem(new TestParagraph())
            };
            var command = new DeleteItemCommand(documentItems, 1);

            command.Execute();

            Assert.AreEqual(1, documentItems.Count);
        }
Esempio n. 21
0
        public DeleteItemCommandHandlerTest()
        {
            this.mockUnitOfWork     = new Mock <IUnitOfWork>(MockBehavior.Strict);
            this.mockItemRepository = new Mock <IItemRepository>(MockBehavior.Strict);
            this.mockUserRepository = new Mock <IUserRepository>(MockBehavior.Strict);

            this.command = new DeleteItemCommand(5, 10);

            this.handler = new DeleteItemCommandHandler(
                mockUnitOfWork.Object,
                mockItemRepository.Object,
                mockUserRepository.Object);
        }
Esempio n. 22
0
        private void clearItems(UpdateOrderViewModel model, Order order)
        {
            var itemCmd = new DeleteItemCommand(_itemRepository, _itemValidator);

            foreach (var item in order.Items)
            {
                if (!model.Items.Any(i => i.Description == item.Description))
                {
                    itemCmd.Execute(item);
                    AddNotifications(itemCmd);
                }
            }
        }
Esempio n. 23
0
        public void CanCreateCommandAndDeleteItemOnExecute()
        {
            var items = new List <DocumentItem>
            {
                new DocumentItem(new TestParagraph()),
            };

            Assert.AreEqual(items.Count, 1);
            DeleteItemCommand c = new DeleteItemCommand(0, items);

            c.Execute();
            Assert.AreEqual(items.Count, 0);
        }
Esempio n. 24
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent != null)
            {
                var itemId = intent.GetStringExtra("itemId");

                var deleteCommand = new DeleteItemCommand(PCLStorage.FileSystem.Current.LocalStorage);
                deleteCommand.Execute(itemId);

                var manager = NotificationManager.FromContext(context);
                manager.CancelAll();
            }
        }
Esempio n. 25
0
        public async Task Handle_Given_ValidId_Should_Not_ThrowException_And_Should_DeleteItemFromDatabase()
        {
            var oldCount = await this.Context.Items.CountAsync();

            var command = new DeleteItemCommand(DataConstants.SampleItemId);

            await this.handler.Handle(command, CancellationToken.None);

            var newCount = await this.Context.Items.CountAsync();

            newCount
            .Should()
            .Be(oldCount - 1);
        }
        public void ShouldDeleteItemFromDataStorageAndReturnTrue(DeleteItemCommand sut, DbItem item, ID parentId)
        {
            // arrange
            sut.DataStorage.GetFakeItem(item.ID).Returns(item);
            sut.DataStorage.RemoveFakeItem(item.ID).Returns(true);

            sut.Initialize(ItemHelper.CreateInstance(item.ID), parentId);

            // act
            var result = (bool)ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            result.Should().BeTrue();
        }
Esempio n. 27
0
        public void Execute_DeleteItemInvoked()
        {
            // Arrange
            bool isDeleteItemInvoked = false;

            _documentMock.Setup(d => d.DeleteItem(It.IsAny <int>())).Callback(() => isDeleteItemInvoked = true);
            ICommand command = new DeleteItemCommand(1, _documentMock.Object);

            // Act
            command.Execute();

            // Assert
            Assert.True(isDeleteItemInvoked);
        }
        public async Task <DeleteItemResponse> Handle(DeleteItemRequest request, CancellationToken cancellationToken)
        {
            var item    = this.mapper.Map <Item>(request);
            var command = new DeleteItemCommand()
            {
                Parameter = item
            };
            var itemFromDb = await this.commandExecutor.Execute(command);

            return(new DeleteItemResponse()
            {
                Data = this.mapper.Map <Domain.Models.Item>(itemFromDb)
            });
        }
 public UpdateDrugViewModel(AdminShellViewModel containingVm, Drug drugToUpdate)
 {
     updateDrugM             = new UpdateDrugModel(drugToUpdate);
     this.containingVm       = containingVm;
     UpdateDbCommand         = new UpdateInDbCommand(this);
     IsNewDrug               = false;
     BackCommand             = new BackCommand(this);
     IngredientToAdd         = new ActiveIngredient();
     Ingredients             = new ObservableCollection <ActiveIngredient>(updateDrugM.Ingredients);
     AddIngredientCommand    = new AddIngredientToDrugCommand(this);
     DeleteIngredientCommand = new DeleteItemCommand(this);
     FileDialogCommand       = new OpenFileDialogCommand(this);
     ImageUrl = Drug.ImageUrl;
 }
Esempio n. 30
0
        public async Task <IActionResult> DeleteItemAsync(Guid itemId)
        {
            try
            {
                var command = new DeleteItemCommand(itemId, User.Identity.Name);
                await commandHandler.HandleAsync(command);

                return(NoContent());
            }
            catch (ItemNotFoundException)
            {
                return(this.NotFound());
            }
        }