| | 1 | | using Microsoft.Azure.Cosmos.Serialization.HybridRow; |
| | 2 | | using MRA.DTO.Models; |
| | 3 | | using System.Text.Json.Serialization; |
| | 4 | |
|
| | 5 | | namespace MRA.DTO.ViewModels.Art |
| | 6 | | { |
| | 7 | | public class FilterResults |
| | 8 | | { |
| | 9 | | [JsonIgnore] |
| 31 | 10 | | public IEnumerable<DrawingModel> TotalDrawings { get; set; } |
| 62 | 11 | | public IEnumerable<DrawingModel> FilteredDrawings { get; set; } |
| 0 | 12 | | public int FetchedCount { get { return (FilteredDrawings != null ? FilteredDrawings.Count() : 0); } } |
| 0 | 13 | | public int TotalCount { get { return TotalDrawings.Count(); } } |
| 0 | 14 | | public int TotalTime { get { return TotalDrawings.Sum(x => x.Time); } } |
| 0 | 15 | | public bool MoreToFetch { get { return FetchedCount < TotalCount; } } |
| | 16 | |
|
| 31 | 17 | | public IEnumerable<string> FilteredDrawingCharacters { get; set; } |
| 0 | 18 | | public int NDrawingCharacters { get { return FilteredDrawingCharacters.Count(); } } |
| 31 | 19 | | public IEnumerable<string> FilteredDrawingModels { get; set; } |
| 0 | 20 | | public int NDrawingModels { get { return FilteredDrawingModels.Count(); } } |
| 31 | 21 | | public IEnumerable<int> FilteredDrawingStyles { get; set; } |
| 0 | 22 | | public int NDrawingTypes { get { return FilteredDrawingStyles.Count(); } } |
| 31 | 23 | | public IEnumerable<int> FilteredDrawingProductTypes { get; set; } |
| 0 | 24 | | public int NDrawingProductTypes { get { return FilteredDrawingProductTypes.Count(); } } |
| 31 | 25 | | public IEnumerable<string> FilteredDrawingProducts { get; set; } |
| 0 | 26 | | public int NDrawingProducts { get { return FilteredDrawingProducts.Count(); } } |
| 31 | 27 | | public IEnumerable<int> FilteredDrawingSoftwares { get; set; } |
| 0 | 28 | | public int NDrawingSoftwares { get { return FilteredDrawingSoftwares.Count(); } } |
| 31 | 29 | | public IEnumerable<int> FilteredDrawingPapers { get; set; } |
| 0 | 30 | | public int NDrawingPapers { get { return FilteredDrawingPapers.Count(); } } |
| 31 | 31 | | public int NDrawingFavorites { get; set; } |
| 31 | 32 | | public IEnumerable<string> FilteredCollections { get; set; } |
| 0 | 33 | | public int NDrawingCollections { get { return FilteredCollections.Count(); } } |
| | 34 | |
|
| | 35 | |
|
| 31 | 36 | | public FilterResults(IEnumerable<DrawingModel> drawings, IEnumerable<CollectionModel> collections, DrawingFilter |
| | 37 | | { |
| 31 | 38 | | TotalDrawings = drawings; |
| 31 | 39 | | FilteredDrawingCharacters = drawings.Select(x => x.Name).Distinct().Where(x => !string.IsNullOrEmpty(x)); |
| 31 | 40 | | FilteredDrawingModels = drawings.Select(x => x.ModelName).Distinct().Where(x => !string.IsNullOrEmpty(x)); |
| 31 | 41 | | FilteredDrawingStyles = drawings.Select(x => (int) x.Type).Distinct(); |
| 31 | 42 | | FilteredDrawingProductTypes = drawings.Select(x => (int) x.ProductType).Distinct(); |
| 31 | 43 | | FilteredDrawingProducts = drawings.Select(x => x.ProductName).Distinct().Where(x => !string.IsNullOrEmpty(x) |
| 31 | 44 | | FilteredDrawingSoftwares = drawings.Select(x => (int) x.Software).Distinct().Where(x => x > 0); |
| 31 | 45 | | FilteredDrawingPapers = drawings.Select(x => (int) x.Paper).Distinct().Where(x => x > 0); |
| 96 | 46 | | NDrawingFavorites = drawings.Count(x => x.Favorite); |
| | 47 | |
|
| 96 | 48 | | var ids = drawings.Select(x => x.Id).ToList(); |
| 31 | 49 | | FilteredCollections = collections |
| 0 | 50 | | .Where(c => c.Drawings.Any(d => ids.Contains(d.Id))) |
| 31 | 51 | | .Select(x => x.Id); |
| | 52 | |
|
| 31 | 53 | | FilteredDrawings = drawings; |
| 31 | 54 | | if (filter.PageSize > 0 && filter.PageNumber > 0) |
| | 55 | | { |
| 0 | 56 | | FilteredDrawings = drawings.Skip((filter.PageNumber - 1) * filter.PageSize) |
| 0 | 57 | | .Take(filter.PageSize); |
| | 58 | | } |
| 31 | 59 | | } |
| | 60 | | } |
| | 61 | | } |