Пример #1
0
        public IActionResult OnPostBuy(double?ServicePrice, double?ProductPrice)
        {
            if (ModelState.IsValid)
            {
                var customer = customerData.GetCustomerById(Visit.CustomerId.Value);
                Visit.Customer = customer;

                if (ProductPrice.HasValue && ProductPrice.Value > 0)
                {
                    Visit.BuyProduct(ProductPrice.Value);
                    ProductPrice = 0;
                }
                if (ServicePrice.HasValue && ServicePrice.Value > 0)
                {
                    Visit.BuyService(ServicePrice.Value);
                    ServicePrice = 0;
                }
            }

            Message = Visit.CustomerId == null ? "No customer selected." : $"Total expences: {Visit.TotalExpences()}";
            var customers = customerData.GetCustomers().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" });

            Customers = new SelectList(customers, "Id", "Display");
            return(Page());
        }