private async void LoadItemList()
        {
            if (_mainWindowViewModel.ConnectionStatus != DatabaseConnectionStatus.Connected)
            {
                _mainWindowViewModel.ShowErrorMessage("出错了", "数据库未连接");
                return;
            }

            try
            {
                var itemList = await DoLoadItemList();

                foreach (var item in itemList)
                {
                    ItemList.Add(item);
                }

                EditItemCommand.RaiseCanExecuteChanged();
                CopyItemCommand.RaiseCanExecuteChanged();
                DeleteItemCommand.RaiseCanExecuteChanged();
            }
            catch (Exception e)
            {
                _mainWindowViewModel.ShowErrorMessage("加载出错", e.Message);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Put(Guid id, EditItemCommand request)
        {
            request.Id = id;
            var result = await _mediator.Send(request);

            return(Ok(result));
        }
Esempio n. 3
0
        /// <summary>
        /// Исключения:
        ///   System.ArgumentNullException:
        ///     Параметр model имеет значение null.
        /// </summary>
        /// <param name="model"></param>
        public DetailItemViewModel(IItemModelAdapter <DataModelType> model,
                                   IDataDetailViewModelCreator <DataModelType, DataDetailViewModelType> viewModelCreator,
                                   IItemModelAdapterCreator <DataModelType> itemModelCreator)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model can't be null");
            }
            if (viewModelCreator == null)
            {
                throw new ArgumentNullException("viewModelCreator can't be null");
            }
            if (itemModelCreator == null)
            {
                throw new ArgumentNullException("itemModelCreator can't be null");
            }

            _model          = model;
            _model.Updated += OnUpdate;
            UpdateCommand   = new UpdateItemCommand <DataModelType, DataDetailViewModelType>(this);
            EditCommand     = new EditItemCommand <DataModelType, DataDetailViewModelType>(this);
            SaveCommand     = new SaveItemCommand <DataModelType, DataDetailViewModelType>(this);

            Debug.Assert(_model.DataModel != null);
            _viewModelCreator = viewModelCreator;
            _itemModelCreator = itemModelCreator;
            DataViewModel     = _viewModelCreator.CreateDataDetailViewModel(_model.DataModel);
        }
Esempio n. 4
0
        public void should_have_error_when_GenreId_is_null()
        {
            var editItemCommand = new EditItemCommand {
                Price = new Money()
            };

            _validator.ShouldHaveValidationErrorFor(x => x.GenreId, editItemCommand);
        }
Esempio n. 5
0
        public void should_have_error_when_GenreId_doesnt_exist()
        {
            _mediatorMock
            .Setup(x => x.Send(It.IsAny <GetGenreCommand>(), CancellationToken.None))
            .ReturnsAsync(() => null);

            var editItemCommand = new EditItemCommand {
                Price = new Money(), GenreId = Guid.NewGuid()
            };

            _validator.ShouldHaveValidationErrorFor(x => x.GenreId, editItemCommand);
        }
Esempio n. 6
0
 public ItemPopupViewModel()
 {
     isreadonly      = true;
     isreadonly_memo = true;
     IsCategoryPopup = false;
     ItemPopupCloseCommandProperty    = new ItemPopupCloseCommand();
     ItemPopupTitleBarCommandProperty = new ItemPopupTitleBarCommand();
     editItemCommandProperty          = new EditItemCommand();
     editItemMemoCommandProperty      = new EditItemMemoCommand();
     itemPopupCategoryCommandProperty = new ItemPopupCategoryCommand();
     SearchItemPopupCloseProperty     = new SearchItemPopupCloseCommand();
 }
        public async Task <IActionResult> Put(Guid id, EditItemCommand request)
        {
            request.Id = id;
            var result = await _mediator.Send(request);

            var hateoasResult = new ItemHateoasResponse {
                Data = result
            };
            await _linksService.AddLinksAsync(hateoasResult);

            return(Ok(hateoasResult));
        }
        public ActionResult Edit(ItemViewModel itemViewModel)
        {
            if (ModelState.IsValid)
            {
                var editItemCommand = new EditItemCommand();
                Mapper.CreateMap<ItemViewModel, EditItemCommand>();
                Mapper.Map(itemViewModel, editItemCommand);

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

            return View();
        }