Ejemplo n.º 1
0
        //Kid detail view includes: summary, tasks list, available rewards, redeemed reward
        public async Task <ViewResult> Details(
            int KidId,
            string sortOrder,
            string currentFilter,
            string searchString,
            int?pageNumber)
        {
            CheckToast();
            var currentKid = await _kidRepository.GetProfileById(KidId);

            var rewards = await _rewardRepository.GetAllByKidId(KidId);

            int pageSize = 5;

            //Task table sorting
            ViewData["CurrentSort"]   = sortOrder;
            ViewData["NameSortParm"]  = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["PointSortParm"] = sortOrder == "Point" ? "point_desc" : "Point";
            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFilter"] = searchString;
            var vTasks = from v in _appDbContext.VTasks.Where(v => v.KidId == KidId)
                         select v;

            if (!String.IsNullOrEmpty(searchString))
            {
                vTasks = vTasks.Where(v => v.Description.Contains(searchString));
            }
            switch (sortOrder)
            {
            case "name_desc":
                vTasks = vTasks.OrderByDescending(v => v.Description);
                break;

            case "Point":
                vTasks = vTasks.OrderBy(v => v.Point);
                break;

            case "point_desc":
                vTasks = vTasks.OrderByDescending(v => v.Point);
                break;

            default:
                vTasks = vTasks.OrderBy(v => v.Description);
                break;
            }
            var paginatedList = await PaginatedList <VTask> .CreateAsync(vTasks.AsNoTracking(), pageNumber ?? 1, pageSize);

            KidDetailsViewModel kidDetailsViewModel = new KidDetailsViewModel()
            {
                kid = currentKid,
                currentKidVTasks      = vTasks,
                currentKidRewards     = rewards,
                givenTasksCount       = vTasks.Count(),
                pendingTasksCount     = _statistic.countPendingTask(vTasks),
                completeTasksCount    = _statistic.countCompleteTask(vTasks),
                availableRewardsCount = _statistic.countAvailableRewards(rewards),
                redeemedRewardsCount  = _statistic.countRedeemedRewards(rewards),
                myToaster             = MyToaster,
                paginatedList         = paginatedList,
                PhotoPath             = currentKid.PhotoPath
            };

            return(View(kidDetailsViewModel));
        }