// GET: PharmBatches public async Task <IActionResult> Index(string batchStatus, int batchPage) { ViewBag.SelectedBatchStatus = batchStatus; DateTime endTime = DateTime.Today; DateTime startTime = endTime.AddMonths(-6); byte batchStatusId = await repository.BatchStatuses.Where(x => x.BatchStatusName == batchStatus).Select(x => x.BatchStatusId).FirstOrDefaultAsync(); List <PharmBatch> batches = await repository.ListBatchesAsync(); BatchViewModel batchViewModel = new BatchViewModel { Batches = batches.Where(x => x.StartDate >= startTime && x.StartDate <= endTime && x.BatchStatusId == batchStatusId), PagingInfo = new PagingInfo { CurrentPage = 1, ItemsPerPage = 10, TotalItems = string.IsNullOrEmpty(batchStatus)?repository.AllBatches.Count():repository.AllBatches.Where(x => x.StartDate >= startTime && x.StartDate <= endTime && x.BatchStatusId == batchStatusId).Count() }, CurrentBatchStatus = batchStatus }; return(View(batchViewModel)); }