protected virtual void GetProduct() { if (string.IsNullOrWhiteSpace(UPC) || UPC.Length < 7) { return; } var product = Repository.Get(p => p.UPC == UPC).FirstOrDefault(); if (product == null) { Dialoger.ShowMessageAsync(this, "Product", $"No Product found for UPC:[{UPC}]", MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative, OkCancelMessageSettings); } else { var productVM = new P.Product() { Id = product.Id, Name = product.Name, PurchasePrice = product.PurchasePrice, SalePrice = product.SalePrice, Quantity = 0, ///Becasue the ListableViewModel will take care of quantity UPC = product.UPC }; EA.GetEvent <PurchaseAddEvent>().Publish(productVM); } }
protected override async void Save() { var exist = Repository.Get(p => p.UPC == UPC).Count() > 0; if (exist) { await Dialoger.ShowMessageAsync(this, "Inventory", $"Product already exist with UPC:[{UPC}]", MessageDialogStyle.Affirmative, OkCancelMessageSettings); return; } var product = new P.Product() { UPC = UPC, Name = Name, Quantity = Quantity, PurchasePrice = PurchasePrice, SalePrice = SalePrice }; Repository.Add(product); Repository.Save(); UPC = Name = string.Empty; EA.GetEvent <ProductAddEvent>().Publish(product); }
protected override async void Delete() { var dailogResult = await Dialoger.ShowMessageAsync(this, "Supplier", $"Do you want to delete '{Name}' of {Address}", MessageDialogStyle.AffirmativeAndNegative, YesNoMessageSettings); if (dailogResult != MessageDialogResult.Affirmative) { return; } var supplier = Repository.Get(Id); Repository.Remove(supplier); Repository.Save(); EA.GetEvent <SupplierRemoveEvent>().Publish(supplier); }
protected override async void Delete() { var dailogResult = await Dialoger.ShowMessageAsync(this, "Inventory", $"Do you want to delete '{Name}' with UPC: [{UPC}]", MessageDialogStyle.AffirmativeAndNegative, YesNoMessageSettings); if (dailogResult != MessageDialogResult.Affirmative) { return; } var product = Repository.Get(Id); Repository.Remove(product); Repository.Save(); EA.GetEvent <ProductRemoveEvent>().Publish(product); }
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); }