Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.4 kB
0
Indexable
Never
public class OrderManager
{
    private readonly IOrderStore orderStore;
    public OrderManager(IOrderStore orderStore)
    {
        this.orderStore = orderStore;
    }
    public void WriteOutSmallOrders()
    {
        var orders = orderStore.GetOrders();
        SmallOrderFilter filter = new SmallOrderFilter(new OrderWriter(),
                                                       orders);
        filter.WriteOutFiltrdAndPriceSortedOrders(new OrderWriter());
    }
    public void WriteOutLargeOrders()
    {
        var orders = orderStore.GetOrders();
        LargeOrderFilter filter = new LargeOrderFilter(new OrderWriter(),
                                                       orders);
        filter.WriteOutFiltrdAndPriceSortedOrders(new OrderWriter());
    }
}
public class LargeOrderFilter
{
    private IOrderWriter orderWriter;
    private List<Order> orders;
    public LargeOrderFilter(IOrderWriter orderWriter, List<Order> orders)
    {
        filterSize = "100";
        this.orderWriter = orderWriter;
        this.orders = orders;
    }
    protected string filterSize;
    public void WriteOutFiltrdAndPriceSortedOrders(IOrderWriter writer)
    {
        List<Order> filteredOrders = this.FilterOrdersSmallerThan(orders,
                                                                  filterSize);
        Enumerable.OrderBy(filteredOrders, o => o.Price);
        ObservableCollection<Order> observableCollection =
            new ObservableCollection<Order>();
        foreach (Order o in filteredOrders)
        {
            observableCollection.Add(o);
        }
        writer.WriteOrders(observableCollection);
    }
    protected List<Order> FilterOrdersSmallerThan(List<Order> allOrders, s
        tring size)
    {
        List<Order> filtered = new List<Order>();
        for (int i = 0; i <= allOrders.Count; i++)
        {
            int number = orders[i].toNumber(size);
            if (allOrders[i].Size <= number)
            {
                continue;
            }
            else
            {
                filtered.Add(orders[i]);
            }
        }
        return filtered;
    }
}
public class SmallOrderFilter : LargeOrderFilter
{
    public SmallOrderFilter(IOrderWriter orderWriter, List<Order> orders)
        : base(orderWriter, orders)
    {
        filterSize = "10";
    }
}