public IActionResult OnPost() { if (ModelState.IsValid) { var customer = customerInMemory.GetCustomer(Visit.CustomerId.Value); Visit.Customer = customer; foreach (var product in Products) { if (product.Selected) { Visit.AddProduct(product); } } foreach (var service in Services) { if (service.Selected) { Visit.AddService(service); } } Visit = visitInMemory.AddVisit(Visit); return(RedirectToPage("/Visit/List")); } else { Products = productInMemory.GetProducts(); Services = serviceInMemory.GetServices(); return(Page()); } //var customer = customerInMemory.GetCustomer(Visit.CustomerId.Value); //Visit.Customer = customer; //foreach (var product in Products) //{ // if (product.Selected) // { // Visit.AddProduct(product); // } //} //foreach (var service in Services) //{ // if (service.Selected) // { // Visit.AddService(service); // } //} //Visit = visitInMemory.AddVisit(Visit); //return RedirectToPage("/Visit/List"); }