Esempio n. 1
0
        public async Task <IActionResult> Excel(PatientSearch search, int page = 1)
        {
            try
            {
                PatientWhereBuilder patientWhereBuilder = new PatientWhereBuilder(search);

                string searchParams = search != default ? search.ToString() : default;

                List <PatientPreviewViewModel> patientsModel = await GetPage(search, patientWhereBuilder, searchParams, page);

                if (patientsModel == default)
                {
                    return(BadRequest());
                }

                return(await base.FormatModel <PatientPreviewViewModel>(patientsModel, MedicDataLocalization.Patients, 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;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(PatientSearch search, int page = 1)
        {
            try
            {
                string searchParams = search != default ? search.ToString() : default;

                PatientWhereBuilder patientWhereBuilder = new PatientWhereBuilder(search);

                List <PatientPreviewViewModel> patientsModel = await GetPage(search, patientWhereBuilder, searchParams, page);

                string patientsCountKey = $"{MedicConstants.PatientsCount} - {searchParams}";

                if (!base.MedicCache.TryGetValue(patientsCountKey, out int patientsCount))
                {
                    patientsCount = await PatientService.GetPatientsCountAsync(patientWhereBuilder);

                    base.MedicCache.Set(patientsCountKey, patientsCount);
                }

                List <SexOption> sexOptions = base.GetDefaultSexes();

                sexOptions.AddRange(await base.GetSexesAsync());

                return(View(new PatientPageIndexModel()
                {
                    Patients = patientsModel,
                    TotalPages = base.TotalPages((int)search.Length, patientsCount),
                    TotalResults = patientsCount,
                    CurrentPage = page,
                    Title = MedicDataLocalization.Get(MedicDataLocalization.Patients),
                    Search = search,
                    Description = MedicDataLocalization.Get(MedicDataLocalization.Patients),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.PatientsSummary),
                    Sexes = sexOptions
                }));
            }
            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;
            }
        }