Ejemplo n.º 1
0
        private async void OnBuyCarExecute()
        {
            if (Car.AskingPrice * 0.8 >= Price)
            {
                InvalidPriceVisibility = Visibility.Visible;
                return;
            }
            var result = await MessageDialogService.ShowOkCancelDialogAsync($"Do you really want to buy {Car.CarModel.Manufacturer} {Car.CarModel.Model} {Car.ManufactureYear}?",
                                                                            "Confirmation");

            if (result == MessageDialogResult.Cancel)
            {
                _eventAggregator.GetEvent <OpenCarListEvent>().Publish(new OpenCarListEventArgs());
                return;
            }
            //injecting data from another repository is not allowed when save changes is reqired
            //additional function is created in person repository
            CarSale cars_Sold = new CarSale
            {
                SalePrice = Price,
                Date      = Date
            };
            await _personRepository.AddNewSaleAsync(Car.Id, Customer.Id, cars_Sold);

            await _carRepository.CarIsSoldAsync(Car.Id);

            _eventAggregator.GetEvent <OpenCarListEvent>().Publish(new OpenCarListEventArgs());
        }