Example #1
0
        private PrintingEditionsInfoModel GetInfo(PrintingEditionFilterModel printingEditionFilter = null, int pageSize = Constants.PRINTINGEDITIONPAGESIZE)
        {
            int dbPrintingEditionsCount = _printingEditionRepository.GetCount(printingEditionFilter);
            int pageCount = (int)Math.Ceiling(dbPrintingEditionsCount / (double)pageSize);
            var filter    = new PrintingEditionFilterModel
            {
                Title = printingEditionFilter.Title,
                Type  = printingEditionFilter.Type
            };
            var dbPrintingEditions = _printingEditionRepository.GetAll(filter).ToList();

            decimal min = default;
            decimal max = default;

            if (dbPrintingEditions.Any())
            {
                min = dbPrintingEditions.Aggregate((currentMin, x) => (currentMin == null || x.Price < currentMin.Price ? x : currentMin)).Price;
                max = dbPrintingEditions.Aggregate((currentMax, x) => (currentMax == null || x.Price > currentMax.Price ? x : currentMax)).Price;
            }
            return(new PrintingEditionsInfoModel
            {
                MaxPrice = max,
                MinPrice = min,
                PageCount = pageCount
            });
        }