| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains; |
| | | 3 | | using OzonDomains.Models; |
| | | 4 | | using Services.DataServices; |
| | | 5 | | using Services.FiltersServices.FilterModels; |
| | | 6 | | using System.Reflection; |
| | | 7 | | using OServices.FiltersServices.FilterModels; |
| | | 8 | | |
| | | 9 | | |
| | | 10 | | namespace Services.FiltersServices.DataFilterManagers |
| | | 11 | | { |
| | | 12 | | public class TransactionDataFilterManager |
| | | 13 | | { |
| | | 14 | | private QueryableDataFilter<Transaction> _filter; |
| | | 15 | | private TransactionDataServices _servcies; |
| | 74 | 16 | | public TransactionDataFilterManager(QueryableDataFilter<Transaction> filter, |
| | 74 | 17 | | TransactionDataServices transactionDataServices) |
| | | 18 | | { |
| | 74 | 19 | | _filter = filter; |
| | 74 | 20 | | _servcies = transactionDataServices; |
| | 74 | 21 | | } |
| | | 22 | | public async Task<List<Transaction>> FilterByFilterData(List<Transaction> standartTransactions, OrderFilterModel |
| | | 23 | | { |
| | 24 | 24 | | bool filterIsNull = AreAllPropertiesNull(filterModel); |
| | 24 | 25 | | bool orderFilterIsNotNull = AreAllPropertiesNull(orderFilterModel); |
| | 24 | 26 | | IQueryable<Transaction> transactions = _servcies.GetTransactions(); |
| | | 27 | | |
| | 24 | 28 | | if (filterIsNull && !orderFilterIsNotNull) |
| | | 29 | | { |
| | 4 | 30 | | return await transactions.ToListAsync(); |
| | | 31 | | } |
| | 20 | 32 | | else if (filterIsNull && orderFilterIsNotNull) |
| | | 33 | | { |
| | 0 | 34 | | return standartTransactions; |
| | | 35 | | } |
| | | 36 | | |
| | 20 | 37 | | transactions = _filter.FilterByString(transactions, tr => tr.CreateBy, filterModel.CreateBy); |
| | 20 | 38 | | transactions = _filter.FilterByDate(transactions, tr => tr.CreatedDateTime, filterModel.CreatedDateTime); |
| | 20 | 39 | | transactions = _filter.FilterByEnum(transactions, t => t.Type, filterModel.Type); |
| | | 40 | | |
| | 20 | 41 | | return await transactions.ToListAsync(); |
| | 24 | 42 | | } |
| | | 43 | | |
| | | 44 | | public async Task<List<Transaction>> FilterByRadioButton(List<Transaction> filterModel, string buttonState) |
| | | 45 | | { |
| | 2 | 46 | | await Task.CompletedTask; |
| | 2 | 47 | | throw new NotImplementedException(); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public bool AreAllPropertiesNull(TransactionFilterModel model) |
| | | 51 | | { |
| | 33 | 52 | | PropertyInfo[] properties = typeof(TransactionFilterModel).GetProperties(); |
| | | 53 | | |
| | 182 | 54 | | foreach (PropertyInfo prop in properties) |
| | | 55 | | { |
| | 70 | 56 | | if (prop.Name == nameof(TransactionFilterModel.Type)) |
| | | 57 | | { |
| | 33 | 58 | | if (model.Type.HasValue && model.Type != TransactionType.All) |
| | | 59 | | { |
| | 10 | 60 | | return false; |
| | | 61 | | } |
| | | 62 | | } |
| | 37 | 63 | | else if (prop.Name == nameof(TransactionFilterModel.CreateBy)) |
| | | 64 | | { |
| | 23 | 65 | | if (!string.IsNullOrEmpty(model.CreateBy) && model.CreateBy != "Все") |
| | | 66 | | { |
| | 9 | 67 | | return false; |
| | | 68 | | } |
| | | 69 | | } |
| | 14 | 70 | | else if (prop.Name == nameof(TransactionFilterModel.CreatedDateTime)) |
| | | 71 | | { |
| | 14 | 72 | | if (model.CreatedDateTime.HasValue) |
| | | 73 | | { |
| | 5 | 74 | | return false; |
| | | 75 | | } |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | |
| | 9 | 79 | | return true; |
| | | 80 | | } |
| | | 81 | | public bool AreAllPropertiesNull(OrderFilterModel model) |
| | | 82 | | { |
| | 35 | 83 | | PropertyInfo[] properties = typeof(OrderFilterModel).GetProperties(); |
| | | 84 | | |
| | 867 | 85 | | foreach (PropertyInfo prop in properties) |
| | | 86 | | { |
| | 416 | 87 | | object? value = prop.GetValue(model); |
| | 416 | 88 | | if (value != null) |
| | | 89 | | { |
| | 35 | 90 | | return false; |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | |
| | 0 | 94 | | return true; |
| | | 95 | | } |
| | | 96 | | } |
| | | 97 | | } |