Ejemplo n.º 1
0
        public ItemViewModel()
        {
            assignmentViewModel = ServiceContainer.Resolve <AssignmentViewModel> ();

            saveAssignmentItemCommand = new DelegateCommand(obj => {
                var item = obj as AssignmentItem;
                if (item != null && assignmentViewModel.SelectedAssignment != null)
                {
                    SaveAssignmentItemAsync(assignmentViewModel.SelectedAssignment, item);
                }
            });

            searchItemsCommand = new DelegateCommand(async _ => {
                await LoadItemsAsync();
                var items = new List <Item> ();
                foreach (var item in Items)
                {
                    if (item.Name.ToLower().Contains(SearchText.ToLower()) || item.Number.ToLower().Contains(SearchText.ToLower()))
                    {
                        items.Add(item);
                    }
                }
                SearchItems = items;
            });

            addItemCommand = new DelegateCommand(_ => {
                if (addItemPopUp != null && addItemPopUp.IsOpen)
                {
                    addItemPopUp.IsOpen = false;
                }
                addItemPopUp                   = new Popup();
                addItemPopUp.Height            = Window.Current.Bounds.Height;
                addItemPopUp.Width             = Constants.PopUpWidth;
                AddItemFlyoutPanel flyoutpanel = new AddItemFlyoutPanel();
                flyoutpanel.Width              = addItemPopUp.Width;
                flyoutpanel.Height             = addItemPopUp.Height;
                addItemPopUp.Child             = flyoutpanel;
                addItemPopUp.SetValue(Canvas.LeftProperty, Window.Current.Bounds.Width - Constants.PopUpWidth);
                addItemPopUp.SetValue(Canvas.TopProperty, 0);
                addItemPopUp.IsOpen = true;
                SearchText          = string.Empty;
                SearchItemsCommand.Invoke();
            });

            cancelAddItemCommand = new DelegateCommand(_ => {
                addItemPopUp.IsOpen = false;
            });

            deleteItemCommand = new DelegateCommand(async _ => {
                if (selectedItem != null)
                {
                    await DeleteAssignmentItemAsync(assignmentViewModel.SelectedAssignment, selectedItem);
                    await LoadAssignmentItemsAsync(assignmentViewModel.SelectedAssignment);
                }
            });
        }
Ejemplo n.º 2
0
        public void SearchItemsCommandTest()
        {
            var db = DataRepository.GetDataRepository;

            Assert.NotNull(db);
            var user        = db.Load <UserDetail>("steph");
            var userManager = new UserManager(db);

            UserManager.GetUserManager.LoginUser(user);


            var searchFilter = new SearchFilterOptions
            {
                User = UserManager.GetUserManager.CurrentUser(),
                SiteLocationEnabled             = false,
                SearchFilterEnabled             = true,
                SearchText                      = "Airway Kit",
                SelectEquipmentUnitsEnabled     = false,
                SelectItemStatusValuesEnabled   = false,
                SelectItemCategoryValuesEnabled = false
            };

            Assert.NotNull(searchFilter, nameof(SearchFilterOptions));
            var resultVM = new TestDetailsViewModel();

            Assert.NotNull(resultVM, nameof(TestDetailsViewModel));
            var onSelectionChangedCommand = new OnSelectionChangedCommand(resultVM);

            Assert.NotNull(onSelectionChangedCommand, nameof(OnSelectionChangedCommand));
            var searchResultViewModel = new SearchResultViewModel(onSelectionChangedCommand);

            Assert.NotNull(searchResultViewModel, nameof(SearchResultViewModel));
            var searchCmd = new SearchItemsCommand(QueryResultEntitySelector.ItemType, searchResultViewModel);

            Assert.NotNull(searchCmd, nameof(SearchItemsCommand));

            Assert.IsTrue(searchCmd.CanExecute(searchFilter));

            Assert.IsNull(resultVM.CurrentItem);                           // nothing selected to display details of
            Assert.That(searchResultViewModel.Items.Count, Is.EqualTo(0)); // no search results or empty search results
            searchCmd.Execute(searchFilter);
            searchCmd.WaitForSearchToComplete();
            Assert.That(searchResultViewModel.Items.Count, Is.GreaterThan(0));

            searchResultViewModel.SelectedItem = searchResultViewModel.Items.First();
            Assert.NotNull(searchResultViewModel.SelectedItem);
            Assert.NotNull(resultVM.CurrentItem);

            Assert.AreNotEqual(Guid.Empty, resultVM.CurrentItem.id);
            Assert.NotNull(resultVM.CurrentItem.entityType);
            Assert.NotNull(resultVM.CurrentItem.entity);
        }
Ejemplo n.º 3
0
        public void ReplaceItemCommand()
        {
            var db = DataRepository.GetDataRepository;

            Assert.NotNull(db);
            var user        = db.Load <UserDetail>("steph");
            var userManager = new UserManager(db);

            UserManager.GetUserManager.LoginUser(user);

            var cmd = new ReplaceItemCommand();

            Assert.NotNull(cmd, nameof(ReplaceItemCommand));

            var item = db.Load <ItemInstance>(SampleItemInstance);

            Assert.NotNull(item);
            // force known value
            item.status = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Available");
            db.Save(item);
            item = db.Load <ItemInstance>(SampleItemInstance);
            Assert.That(item.status.name, Is.EqualTo("Available"));

            Assert.IsTrue(cmd.CanExecute(item));
            cmd.Execute(item);
            Assert.That(item.status.name, Is.EqualTo("Out for Service"));

            // verify a new item created
            var searchFilter = new SearchFilterOptions
            {
                User = UserManager.GetUserManager.CurrentUser(),
                SiteLocationEnabled = false,
                SearchFilterEnabled = true,
                SearchText          = SampleItemNumber,
                ItemTypeMatching    = SearchFilterItemMatching.OnlyExact,
                //AllowItemsRemovedFromService = false, // required or query below may return old item instead of new one
                SelectEquipmentUnitsEnabled     = false,
                SelectItemStatusValuesEnabled   = false,
                SelectItemCategoryValuesEnabled = false
            };

            Assert.NotNull(searchFilter, nameof(SearchFilterOptions));
            var resultVM = new TestDetailsViewModel();

            Assert.NotNull(resultVM, nameof(TestDetailsViewModel));
            var onSelectionChangedCommand = new OnSelectionChangedCommand(resultVM);

            Assert.NotNull(onSelectionChangedCommand, nameof(OnSelectionChangedCommand));
            var searchResultViewModel = new SearchResultViewModel(onSelectionChangedCommand);

            Assert.NotNull(searchResultViewModel, nameof(SearchResultViewModel));
            var searchCmd = new SearchItemsCommand(QueryResultEntitySelector.ItemType, searchResultViewModel);

            Assert.NotNull(searchCmd, nameof(SearchItemsCommand));
            //var searchFilterOptionsViewModel = new SearchFilterOptionsViewModel(searchFilter, QueryResultEntitySelector.ItemInstance, searchResultViewModel);
            //Assert.NotNull(searchFilterOptionsViewModel);

            Assert.IsTrue(searchCmd.CanExecute(searchFilter));

            Assert.IsNull(resultVM.CurrentItem);                           // nothing selected to display details of
            Assert.That(searchResultViewModel.Items.Count, Is.EqualTo(0)); // no search results or empty search results
            searchCmd.Execute(searchFilter);
            searchCmd.WaitForSearchToComplete();
            Assert.That(searchResultViewModel.Items.Count, Is.GreaterThan(0));

            searchResultViewModel.SelectedItem = searchResultViewModel.Items.First();
            Assert.NotNull(searchResultViewModel.SelectedItem);
            Assert.NotNull(resultVM.CurrentItem);
            Assert.That(resultVM.CurrentItem.id, Is.Not.EqualTo(item.id));

            // delete new item and restore old item to Available
            var newItem = db.Load <ItemInstance>(resultVM.CurrentItem.id);

            Assert.That(newItem.status.name, Is.EqualTo("Available"));
            item.status             = db.ReferenceData[nameof(ItemStatus)].ByName <ItemStatus>("Available");
            item.removedServiceDate = null;
            db.Delete(newItem);
            Assert.IsFalse(db.Exists(newItem));
            db.Save(item);
            item = db.Load <ItemInstance>(SampleItemInstance);
            Assert.That(item.status.name, Is.EqualTo("Available"));
        }
Ejemplo n.º 4
0
 public SearchFilterOptionsViewModel(SearchFilterOptions searchFilterOptions, QueryResultEntitySelector resultEntitySelector, SearchResultViewModel searchResultViewModel) : base()
 {
     SearchFilterCommand = new SearchItemsCommand(resultEntitySelector, searchResultViewModel);
     this.SearchFilter   = searchFilterOptions;
 }
        private void PopulateTiles()
        {
            if (_authContext.CheckPermission(PredefinedPermissions.MarketingPromotionsManage))
            {
                _tileManager.AddTile(new NumberTileItem()
                {
                    IdModule        = NavigationNames.MenuName,
                    IdTile          = "ActivePromotions",
                    TileTitle       = "Active promotions",
                    TileCategory    = NavigationNames.ModuleName,
                    Order           = 0,
                    IdColorSchema   = TileColorSchemas.Schema3,
                    NavigateCommand = new DelegateCommand(() => OnUIThread(async() =>
                    {
                        if (NavigateToTabPage(NavigationNames.HomeName))
                        {
                            SearchFilterState = SearchFilterStates[0];
                            await Task.Run(() => Thread.Sleep(300));                              // we need some time to parse xaml
                            SearchItemsCommand.Execute();
                        }
                    })),
                    Refresh = async(tileItem) =>
                    {
                        try
                        {
                            using (var repository = _marketingRepository.GetRepositoryInstance())
                            {
                                if (tileItem is NumberTileItem)
                                {
                                    var query = await Task.Factory.StartNew(() => repository.Promotions.Count());
                                    (tileItem as NumberTileItem).TileNumber = query.ToString();
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                });
            }

            if (_authContext.CheckPermission(PredefinedPermissions.MarketingPromotionsManage))
            {
                _tileManager.AddTile(new IconTileItem()
                {
                    IdModule        = NavigationNames.MenuName,
                    IdTile          = "NewPromotion",
                    TileIconSource  = "Icon_Module_Promotions",
                    TileTitle       = "New promotion",
                    TileCategory    = NavigationNames.ModuleName,
                    Order           = 1,
                    IdColorSchema   = TileColorSchemas.Schema1,
                    NavigateCommand = new DelegateCommand(() => OnUIThread(async() =>
                    {
                        if (NavigateToTabPage(NavigationNames.HomeName))
                        {
                            await Task.Run(() => Thread.Sleep(300));                                             // we need some time to parse xaml
                            CreateItemCommand.Execute();
                        }
                    }))
                });
            }
        }
 public void SearchGroups(String Groupname)
 {
     SearchItemsCommand.Execute(null);
 }
Ejemplo n.º 7
0
 public void SearchUser(String Username)
 {
     SearchItemsCommand.Execute(null);
 }