public IActionResult Statistics(int page = 1, string name = "", bool onlyIntactShips = false, FilterMoveState filterMoveState = FilterMoveState.All, SortState sortOrder = SortState.NameAsc) { int pageSize = 3; var records = this.statisticsService.GetStatisticsRecords(name, onlyIntactShips, sortOrder, filterMoveState); var count = records.Count(); var items = records.Skip((page - 1) * pageSize).Take(pageSize).ToList(); StatisticsViewModel viewModel = new StatisticsViewModel { PageViewModel = new PageViewModel(count, page, pageSize), StatisticsRecords = items, SortedStatisticsRecord = new SortedStatisticsRecord(sortOrder), FilterStatisticsRecord = new FilterStatisticsRecord(name, filterMoveState, onlyIntactShips) }; return(View(viewModel)); }
public FilterStatisticsRecord(string name, FilterMoveState filterMoveState, bool onlyIntactShips) { this.SelectedName = name; this.OnlyIntactShips = onlyIntactShips; this.FilterMoveState = filterMoveState; }
public List <StatisticsRecord> GetStatisticsRecords(string name, bool onlyIntactShips, SortState sortOrder, FilterMoveState filterMoveState) { var statisticsRecords = this.db.StatisticsRecords.GetAll(); if (!String.IsNullOrEmpty(name)) { statisticsRecords = statisticsRecords.Where(sr => sr.Winner == name); } if (onlyIntactShips) { // Find only games where ships don't contain injured cells statisticsRecords = statisticsRecords.Where(sr => sr.WinnerShips.Where(ws => ws.InjuredCells > 0).Count() == 0); } switch (filterMoveState) { case FilterMoveState.Minimum: statisticsRecords = statisticsRecords.Where(sr => sr.MoveCount <= 40); break; case FilterMoveState.Medium: statisticsRecords = statisticsRecords.Where(sr => sr.MoveCount > 40 && sr.MoveCount <= 100); break; case FilterMoveState.Maximum: statisticsRecords = statisticsRecords.Where(sr => sr.MoveCount > 100); break; } switch (sortOrder) { case SortState.NameAsc: statisticsRecords = statisticsRecords.OrderBy(sr => sr.Winner); break; case SortState.NameDesc: statisticsRecords = statisticsRecords.OrderByDescending(sr => sr.Winner); break; case SortState.MoveCountAsc: statisticsRecords = statisticsRecords.OrderBy(sr => sr.MoveCount); break; case SortState.MoveCountDesc: statisticsRecords = statisticsRecords.OrderByDescending(sr => sr.MoveCount); break; case SortState.ShipCountAsc: statisticsRecords = statisticsRecords.OrderBy(sr => sr.WinnerShips.Count()); break; case SortState.ShipCountDesc: statisticsRecords = statisticsRecords.OrderByDescending(sr => sr.WinnerShips.Count()); break; } return(statisticsRecords.ToList()); }