Esempio n. 1
0
        /**
         * Method to update references, used when a
         * new buyingoffer is placed on a salesSupply.
         */
        public void AddBuyingOfferToSalesSupply(SalesSupply sale, BuyingOffer offer)
        {
            SalesSupply dbSalesSupply = SalesSupplies
                                        .Where(s => s.Id == sale.Id)
                                        .FirstOrDefault();

            dbSalesSupply.HighestBuyingOffer = offer;
            dbSalesSupply.HighestPrice       = offer.PriceAmount;
            offer.SalesSupply = dbSalesSupply;
        }
Esempio n. 2
0
        //------------------------------ EVENTHANDLERS --------------------------------------------------------

        /**
         * This method assigns the best BuyingOffer
         * of a salesSupply to a new value object,
         * overwriting the existing value.
         */
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            string priceStr = TxtBoxPriceOffer.Text;
            double oldOffer = _salesSupply.HighestPrice;

            if (priceStr == null || priceStr == "" || priceStr == "Angiv pris")
            {
                ErrorLabel.Content    = "Indtast venligst et beløb.";
                ErrorLabel.Visibility = Visibility.Visible;
            }
            else
            {
                try
                {
                    double price = Convert.ToDouble(priceStr);

                    if (price > oldOffer && !priceStr.Contains("-"))
                    {
                        BuyingOffer offer = new BuyingOffer(price, _salesSupply, _buyerInfo);
                        _context.AddBuyingOfferToSalesSupply(_salesSupply, offer);
                        _context.SaveChanges();

                        _main.ListBox.ItemsSource = null;
                        _main.ListBox.ItemsSource = _context.GetSalesSupplies();
                        _main.Show();
                        this.Hide();
                    }
                    else if (priceStr.Contains("-"))
                    {
                        ErrorLabel.Content    = "Indtast venligst et positivt tal.";
                        ErrorLabel.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        ErrorLabel.Content    = "Indtast venligst et beløb som overgår det forrige bud.";
                        ErrorLabel.Visibility = Visibility.Visible;
                    }
                }
                catch (Exception)
                {
                    ErrorLabel.Content    = "Indtast venligst et tal.";
                    ErrorLabel.Visibility = Visibility.Visible;
                }
            }
        }