Ejemplo n.º 1
0
        public async Task <IActionResult> SearchTestsGet(FilterModel filterModel)
        {
            if (filterModel.SearchString is null)
            {
                filterModel.SearchString = "";
            }

            if (filterModel.TestRatingFrom is null || filterModel.TestRatingFrom < 0)
            {
                filterModel.TestRatingFrom = 0;
            }

            if (filterModel.TestRatingTo is null || filterModel.TestRatingTo < 0)
            {
                filterModel.TestRatingTo = Int32.MaxValue;
            }

            filterModel.SwapRatingBounds();

            if (filterModel.TestDurationFrom is null)
            {
                filterModel.TestDurationFrom = new TimeSpan(0, 0, 0);
            }

            if (filterModel.TestDurationTo is null)
            {
                filterModel.TestDurationTo = new TimeSpan(23, 59, 0);
            }

            filterModel.SwapDurationBounds();

            var tests = await _testingPlatform.TestManager
                        .GetAll()
                        .Where(t => t.TestCode != null &&
                               t.TestName.Contains(filterModel.SearchString, StringComparison.OrdinalIgnoreCase) &&
                               t.TestMarks.Count(tm => tm.EnjoyedTest) - t.TestMarks.Count(tm => !tm.EnjoyedTest) >= filterModel.TestRatingFrom &&
                               t.TestMarks.Count(tm => tm.EnjoyedTest) - t.TestMarks.Count(tm => !tm.EnjoyedTest) <= filterModel.TestRatingTo &&
                               t.TestDuration >= filterModel.TestDurationFrom &&
                               t.TestDuration <= filterModel.TestDurationTo)
                        .Take(_loadConfig.Value.TakeAmount)
                        .ToListAsync();

            if (tests is null)
            {
                return(NotFound());
            }

            ViewBag.AjaxTakeAmount = _loadConfig.Value.AjaxTakeAmount;
            return(View(tests));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetSharedTestsAjax(int?skipAmount, FilterModel filterModel)
        {
            if (skipAmount is null)
            {
                return(NotFound());
            }

            if (filterModel.SearchString is null)
            {
                filterModel.SearchString = "";
            }

            if (filterModel.TestRatingFrom is null || filterModel.TestRatingFrom < 0)
            {
                filterModel.TestRatingFrom = 0;
            }

            if (filterModel.TestRatingTo is null || filterModel.TestRatingTo < 0)
            {
                filterModel.TestRatingTo = Int32.MaxValue;
            }

            filterModel.SwapRatingBounds();

            if (filterModel.TestDurationFrom is null)
            {
                filterModel.TestDurationFrom = new TimeSpan(0, 0, 0);
            }

            if (filterModel.TestDurationTo is null)
            {
                filterModel.TestDurationTo = new TimeSpan(23, 59, 0);
            }

            filterModel.SwapDurationBounds();

            var tests = await _testingPlatform.TestManager
                        .GetAll()
                        .Where(t => t.TestCode != null &&
                               t.TestName.Contains(filterModel.SearchString, StringComparison.OrdinalIgnoreCase) &&
                               t.TestMarks.Count(tm => tm.EnjoyedTest) - t.TestMarks.Count(tm => !tm.EnjoyedTest) >= filterModel.TestRatingFrom &&
                               t.TestMarks.Count(tm => tm.EnjoyedTest) - t.TestMarks.Count(tm => !tm.EnjoyedTest) <= filterModel.TestRatingTo &&
                               t.TestDuration >= filterModel.TestDurationFrom &&
                               t.TestDuration <= filterModel.TestDurationTo)
                        .Skip(skipAmount.Value)
                        .Take(_loadConfig.Value.AjaxTakeAmount)
                        .ToListAsync();

            var optimizedTests = tests.Select(t =>
                                              new
            {
                t.Id,
                t.TestName,
                t.CreationDate,
                t.TestCode,
                t.TestDuration,
                testRating = t.TestMarks.Count(tm => tm.EnjoyedTest) - t.TestMarks.Count(tm => !tm.EnjoyedTest),
                t.AppUser.UserName
            });

            return(Json(optimizedTests));
        }