Beispiel #1
0
        public PurchaseOrderMainViewModel(
            IProductRepository productRepository,
            ISupplierRepository supplierRepository,
            IPurchaseOrderRepository purchaseOrderRepository,
            IPurchaseOrderDetailRepository purchaseOrderDetailRepository,
            IEventAggregator ea)
        {
            ProductLocatingViewModel   = new ProductLocatingViewModel(productRepository, ea);
            PurchaseOrderListViewModel = new PurchaseOrderListViewModel(ea);
            SupplierSelectionViewModel = new SupplierSelectionViewModel(supplierRepository, ea);
            PurchaseAllOrdersViewModel = new PurchaseAllOrdersViewModel(purchaseOrderRepository, ea);

            SubmitCommand                  = new DelegateCommand(Submit, CanSubmit);
            _productRepository             = productRepository;
            _supplierRepository            = supplierRepository;
            _purchaseOrderDetailRepository = purchaseOrderDetailRepository;
            EA = ea;
            EA.GetEvent <CanSubmitEvent>().Subscribe(RaiseCanSubmitEvent);
            EA.GetEvent <UpdatePurchaseDetails>().Subscribe(OnUpdatePurchaseDetails);
        }
Beispiel #2
0
        private async void Submit()
        {
            var progress = await Dialoger.ShowProgressAsync(this, "Purchase Order", "Please wait. Order is in progress", settings : OkCancelMessageSettings);

            var maxValue = PurchaseOrderListViewModel.Items.Count;

            progress.Minimum = 0;
            progress.Maximum = maxValue;

            var progressValue = 0;
            await Task.Delay(100);

            var purchaseOrder = new M.PurchaseOrder
            {
                SupplierId = SupplierSelectionViewModel.SelectedItem.Id,
                OrderDate  = SupplierSelectionViewModel.OrderDate
            };

            foreach (var item in PurchaseOrderListViewModel.Items)
            {
                var purchasedetail = new M.PurchaseOrderDetail()
                {
                    ProductId     = item.ProductId,
                    PurchasePrice = item.PurchasePrice,
                    SalePrice     = item.SalePrice,
                    Quantity      = item.Quantity,
                };
                purchaseOrder.OrderDetails.Add(purchasedetail);

                var product = _productRepository.Get(purchasedetail.ProductId);

                product.Quantity += purchasedetail.Quantity;

                if (purchasedetail.PurchasePrice > product.PurchasePrice)
                {
                    product.PurchasePrice = purchasedetail.PurchasePrice;
                }

                if (purchasedetail.SalePrice > product.SalePrice)
                {
                    product.SalePrice = purchasedetail.SalePrice;
                }

                _productRepository.Save();

                progressValue++;

                progress.SetProgress(progressValue);
                await Task.Delay(100);
            }

            var supplier = _supplierRepository.Get(purchaseOrder.SupplierId);

            supplier.PurchaseOrders.Add(purchaseOrder);
            _supplierRepository.Save();

            await Task.Delay(100);

            PurchaseOrderListViewModel.Items.Clear();
            PurchaseOrderListViewModel.CalculateTotal();

            EA.GetEvent <SubmittedEvent>().Publish();

            await progress.CloseAsync();

            await Dialoger.ShowMessageAsync(this, "Purchase Order", "Purchase order completed.\nInventory is being updated.", MessageDialogStyle.Affirmative, OkCancelMessageSettings);
        }