public async Task <IActionResult> Excel(CommissionAprSearch search, int page = 1) { try { CommissionAprWhereBuilder commissionAprWhereBuilder = new CommissionAprWhereBuilder(search); string searchParams = search != default ? search.ToString() : default; List <CommissionAprPreviewViewModel> commissionAprs = await GetPage(search, commissionAprWhereBuilder, searchParams, page); if (commissionAprs == default) { return(BadRequest()); } return(await base.FormatModel <CommissionAprPreviewViewModel>(commissionAprs, MedicDataLocalization.CommissionAprs, FormattableFactory)); } catch (Exception ex) { Task <int> _ = MedicLoggerService.SaveAsync(new Log() { Message = ex.Message, InnerExceptionMessage = ex?.InnerException?.Message ?? null, Source = ex.Source, StackTrace = ex.StackTrace, Date = DateTime.Now }); throw; } }
public async Task <IActionResult> Index(CommissionAprSearch search, int page = 1) { try { CommissionAprWhereBuilder commissionAprWhereBuilder = new CommissionAprWhereBuilder(search); string searchParams = search != default ? search.ToString() : default; List <CommissionAprPreviewViewModel> commissionAprs = await GetPage(search, commissionAprWhereBuilder, searchParams, page); string commissionAprsCountKey = $"{MedicConstants.CommissionAprs} - {searchParams}"; if (!base.MedicCache.TryGetValue(commissionAprsCountKey, out int commissionAprsCount)) { commissionAprsCount = await CommissionAprService .GetCommissionAprsCountAsync(commissionAprWhereBuilder); base.MedicCache.Set(commissionAprsCountKey, commissionAprsCount); } List <SexOption> sexOptions = base.GetDefaultSexes(); sexOptions.AddRange(await base.GetSexesAsync()); List <HealthRegionOption> healthRegions = base.GetDefaultHealthRegions(); healthRegions.AddRange(await base.GetHealthRegionsAsync()); return(View(new CommissionAprPageIndexModel() { CommissionAprs = commissionAprs, Title = MedicDataLocalization.Get(MedicDataLocalization.CommissionAprs), Description = MedicDataLocalization.Get(MedicDataLocalization.CommissionAprs), Keywords = MedicDataLocalization.Get(MedicDataLocalization.CommissionAprsSummary), Search = search, CurrentPage = page, TotalPages = base.TotalPages((int)search.Length, commissionAprsCount), TotalResults = commissionAprsCount, Sexes = sexOptions, HealthRegions = healthRegions })); } catch (Exception ex) { Task <int> _ = MedicLoggerService.SaveAsync(new Log() { Message = ex.Message, InnerExceptionMessage = ex?.InnerException?.Message ?? null, Source = ex.Source, StackTrace = ex.StackTrace, Date = DateTime.Now }); throw; } }
private async Task <List <CommissionAprPreviewViewModel> > GetPage(CommissionAprSearch search, CommissionAprWhereBuilder commissionAprWhereBuilder, string searchParams, int page) { int pageLength = (int)search.Length; int startIndex = base.GetStartIndex(pageLength, page); string commissionAprsKey = $"{nameof(CommissionAprPreviewViewModel)} - {startIndex} - {searchParams}"; if (!base.MedicCache.TryGetValue(commissionAprsKey, out List <CommissionAprPreviewViewModel> commissionAprs)) { CommissionAprHelperBuilder helperBuilder = new CommissionAprHelperBuilder(search); commissionAprs = await CommissionAprService .GetCommissionAprsAsync(commissionAprWhereBuilder, helperBuilder, startIndex); base.MedicCache.Set(commissionAprsKey, commissionAprs); } return(commissionAprs); }