1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using Microsoft.EntityFrameworkCore;
- using OOO_WriteAndClear.DBModels;
- using OOO_WriteAndClear.MVP.Models.ProductsUserControlModel;
- using OOO_WriteAndClear.MVP.MVPInterfaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OOO_WriteAndClear.MVP.Models
- {
- public class OrdersUserControlModel : IOrdersUserControlContract.Model
- {
- public OrdersUserControlModel()
- {
- _orders = new List<Order>();
- _ordersFromDB = new List<Order>();
- }
- public ICollection<Order> Orders => _orders;
- public void UpdateOrdersFromDB()
- {
- using(VorobiewTradeContext db = new VorobiewTradeContext())
- {
- _ordersFromDB = db.Orders.Include(a => a.OrderProducts)
- .ThenInclude(a => a.ProductArticleNumberNavigation)
- .Include(a => a.OrderPickupPoint)
- .Include(a => a.OrderStatus)
- .ToList();
- }
- }
- public void FilterAndSorting(FilterByDiscountParameters filterParams, string sortingParams)
- {
- _orders = SortOrders(FiltOrders(_ordersFromDB, filterParams), sortingParams);
- }
- private ICollection<Order> _orders;
- private ICollection<Order> _ordersFromDB;
- private ICollection<Order> FiltOrders(ICollection<Order> orders, FilterByDiscountParameters parameters)
- {
- return orders.Where(a =>
- decimal.ToDouble(a.OrderDiscountPercent * 100) >= parameters.From
- && decimal.ToDouble(a.OrderDiscountPercent * 100) < parameters.Before
- ).ToList();
- }
- private ICollection<Order> SortOrders(ICollection<Order> orders, string sortVarients)
- {
- switch(sortVarients)
- {
- case "По возрастанию":
- return orders.OrderBy(a => a.OrderCost).ToList();
- case "По убыванию":
- return orders.OrderByDescending(a => a.OrderCost).ToList();
- default:
- return orders;
- }
- }
- }
- }
|