1W-RPckb_1

CSharp · Console

/Program.cs

using System;
using System.Linq;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine("Hello World");
	}
	
	public class Test
    {
        public void Method1()
        {
            var tables = Enumerable.Empty<Table>();

            int orderInput = 13000;
            string customerInput = "";
            int employeeInput = 20;

            var q = tables
                .Where(t => t.OrderId == 0 || t.OrderId < orderInput)
                .Where(t => string.IsNullOrWhiteSpace(t.CustomerId) || t.CustomerId == customerInput)
                .Where(t => t.OrderId == 0 || t.OrderId < employeeInput);
        }
        public void Method2()
        {
            var tables = Enumerable.Empty<Table>();

            var aInputModel = new InputModel()
            {
                orderInput = 13000,
                customerInput = "",
                employeeInput = 20,
            };

            var q = tables.Where(t => aInputModel.IsMatch(t));
        }

        public class Table
        {
            public int OrderId { get; set; }
            public string CustomerId { get; set; }
            public int EmployeeId { get; set; }


        }
        public class InputModel
        {
            public int orderInput { get; set; }
            public string customerInput { get; set; }
            public int employeeInput { get; set; }

            private bool IsOrderIdMatch(int orderId) => orderInput == 0 || orderId < orderInput;
            private bool IsCustomerIdMatch(string customerId) => string.IsNullOrWhiteSpace(customerInput) || customerId == customerInput;
            private bool IsEmployeeMatch(int employeeId) => employeeInput == 0 || employeeId < employeeInput;

            public bool IsMatch(Table aTable) => IsOrderIdMatch(aTable.OrderId)
                && IsCustomerIdMatch(aTable.CustomerId)
                && IsEmployeeMatch(aTable.EmployeeId);
        }

    }
}
;