/// <summary> /// Binds the product details. /// </summary> /// <exception cref="System.NotImplementedException"></exception> private void BindProductDetails(object product) { var isExist = LstProductDetails.Where(u => u.Id == CurrentProduct.Id).FirstOrDefault(); if (isExist == null) { LstProductDetails.Add(new ProductDTO { Id = CurrentProduct.Id, Name = CurrentProduct.Name, Quantity = CurrentProduct.Quantity, Retail_Price = CurrentProduct.Retail_Price, Discount = CurrentProduct.Discount, Amount = (CurrentProduct.Quantity * CurrentProduct.Retail_Price) }); } else { var found = LstProductDetails.FirstOrDefault(x => x.Id == CurrentProduct.Id); int i = LstProductDetails.IndexOf(found); var quantity = CurrentProduct.Quantity + found.Quantity; LstProductDetails[i].Quantity = quantity; LstProductDetails[i].Amount = (found.Retail_Price * quantity) - found.Discount; CollectionViewSource.GetDefaultView(this.LstProductDetails).Refresh(); } var amount = LstProductDetails.Select(u => u.Amount).Sum(); var totalDiscount = LstProductDetails.Select(u => u.Discount).Sum(); TotalDiscount = (decimal)totalDiscount; Total = (decimal)amount; Mediator.NotifyColleagues("CloseProductPopUpWindow", false); }
private void EditDataGridCommand() { SelectedProduct.Quantity = ProductQuantity; SelectedProduct.Amount = (decimal)(SelectedProduct.Quantity * SelectedProduct.Retail_Price); bool showErrorMessage = false; if (SelectedDiscountType != null) { if (SelectedDiscountType.Id == 1 && ProductDiscount < SelectedProduct.Amount) { SelectedProduct.Discount = ProductDiscount; SelectedProduct.Amount -= ProductDiscount; } else if (SelectedDiscountType.Id == 2) { decimal discountAmount = (decimal)(SelectedProduct.Amount * (ProductDiscount / 100)); if (discountAmount < SelectedProduct.Amount) { SelectedProduct.Discount = discountAmount; SelectedProduct.Amount -= discountAmount; } else { showErrorMessage = true; } } else { showErrorMessage = true; } } if (!showErrorMessage) { var totalAmount = LstProductDetails.Select(u => u.Amount).Sum(); var totalDiscount = LstProductDetails.Select(u => u.Discount).Sum(); Total = (decimal)totalAmount; TotalDiscount = (decimal)totalDiscount; IsEditProductEntryPopupOpen = false; } else { IsErrorMessageVisible = Visibility.Visible; } //SelectedProduct.Amount = Amount }