コード例 #1
0
        protected int PromptForCreateOrExist <T>(Func <int> creationFunction, Func <int> existingFunction)
            where T : SEntity
        {
            int  result;
            bool itemExists = StoreManagerApplication.Any <T>();
            bool createItem = true;

            if (itemExists)
            {
                createItem = CUI.PromptForBool($"Create a new {_typeNames[typeof(T)]} or use one that is existing?", "create", "existing");
            }
            else
            {
                Console.WriteLine($"No {_typeNames[typeof(T)]}s exist; please create a {_typeNames[typeof(T)]}.");
            }

            if (createItem)
            {
                // create the item
                result = creationFunction();
            }
            else
            {
                // just get the id
                result = existingFunction();
            }

            return(result);
        }
コード例 #2
0
 private void DisplayOrderDetails()
 {
     // get the order id
     // display its data
     if (!StoreManagerApplication.Any <Order>())
     {
         Console.WriteLine("No orders present");
     }
     else
     {
         int orderId = PromptForId <Order>();
         // Display the order
         DisplayOrder(orderId);
     }
 }
コード例 #3
0
 public void AnyCustomerExists()
 {
     Assert.True(StoreManagerApplication.Any <Customer>(), "No customers were found in the database.");
 }