Exemple #1
0
        public AddProductView(ProductModel product = null)
        {
            InitializeComponent();
            DataContext = ViewModel = new AddProductViewModel(product);
            ViewModel.PropertyChanged += ViewModelOnPropertyChanged;
            Owner = Application.Current.MainWindow;

            Loaded += OnAddProductViewLoaded;
        }
Exemple #2
0
        private void RefreshProductEventTypes(ProductModel model)
        {
            var types = new List<CheckedListItem<EventTypeModel>>();

            foreach (var type in _allEventTypes)
            {
                var isChecked = Product.EventTypes.Select(x => x.EventType).Contains(type.EventType);
                var item = new CheckedListItem<EventTypeModel>(type, isChecked);

                item.PropertyChanged += ItemOnPropertyChanged;
                types.Add(item);
            }

            CheckedEventTypes = new ObservableCollection<CheckedListItem<EventTypeModel>>(types);
        }
Exemple #3
0
        private void ProcessProduct(ProductModel product)
        {
            IsEdit = (product != null);

            Product = (IsEdit) ? product : GetProduct();

            Product.PropertyChanged += ProductOnPropertyChanged;

        }
Exemple #4
0
        public AddProductViewModel(ProductModel model)
        {
            var dataUnitLocator = ContainerAccessor.Instance.GetContainer().Resolve<IDataUnitLocator>();
            _adminDataUnit = dataUnitLocator.ResolveDataUnit<IAdminDataUnit>();

            SaveCommand = new RelayCommand(SaveCommandExecuted, SaveCommandCanExecute);
            CancelCommand = new RelayCommand(CancelCommandExecuted);

            ProcessProduct(model);
        }
Exemple #5
0
        private void EditProductCommandExecuted(ProductModel productModel)
        {
            RaisePropertyChanged("DisableParentWindow");

            SelectedProduct = productModel;

            var view = new AddProductView(productModel);
            view.ShowDialog();

            RaisePropertyChanged("EnableParentWindow");

            if (view.DialogResult != null && view.DialogResult == true)
            {
                _reportsDataUnit.ProductsRepository.Refresh();
                _eventsDataUnit.ProductsRepository.Refresh();
            }
        }
Exemple #6
0
        private async void DeleteProductCommandExecuted(ProductModel productModel)
        {
            if (productModel == null) return;

            bool? dialogResult = null;
            string confirmText = Properties.Resources.MESSAGE_ASK_BEFORE_DELETING_ITEM;

            RaisePropertyChanged("DisableParentWindow");

            RadWindow.Confirm(confirmText, (sender, args) => { dialogResult = args.DialogResult; });

            RaisePropertyChanged("EnableParentWindow");

            if (dialogResult != true) return;

            // Check if product has dependencies
            if (productModel.Product.EventBookedProducts.Any())
            {
                var sb = new StringBuilder();

                sb.AppendLine("Sorry, we can't delete this product :(");
                sb.AppendLine("This product already in use by these events:");

                productModel.Product.EventBookedProducts.Select(x => x.Event.Name).ForEach(x => sb.AppendLine(string.Format("- {0}", x)));

                RaisePropertyChanged("DisableParentWindow");

                RadWindow.Alert(sb.ToString());

                RaisePropertyChanged("EnableParentWindow");

                return;
            }

            // Delete product event types
            var types = await _adminDataUnit.ProductEventTypesRepository.GetAllAsync(x => x.ProductID == productModel.Product.ID);
            _adminDataUnit.ProductEventTypesRepository.Delete(types);

            // Delete product
            _adminDataUnit.ProductsRepository.Delete(productModel.Product);

            await _adminDataUnit.SaveChanges();

            Products.Remove(productModel);
        }