Exemplo n.º 1
0
        public async Task <IActionResult> Excel(TransferSearch search, int page = 1)
        {
            try
            {
                TransferWhereBuilder transferWhereBuilder = new TransferWhereBuilder(search);

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

                List <TransferPreviewViewModel> transfers = await GetPage(search, transferWhereBuilder, searchParams, page);

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

                return(await base.FormatModel <TransferPreviewViewModel>(transfers, MedicDataLocalization.Plannings, 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;
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(TransferSearch search, int page = 1)
        {
            try
            {
                TransferWhereBuilder plannedWhereBuilder = new TransferWhereBuilder(search);

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

                List <TransferPreviewViewModel> trasnfers = await GetPage(search, plannedWhereBuilder, searchParams, page);

                string trasnferCountKey = $"{MedicConstants.Transfers} - {searchParams}";

                if (!base.MedicCache.TryGetValue(trasnferCountKey, out int trasnfersCount))
                {
                    trasnfersCount = await TransferService
                                     .GetTrasnfersCountAsync(plannedWhereBuilder);

                    base.MedicCache.Set(trasnferCountKey, trasnfersCount);
                }

                return(View(new TransferPageIndexModel()
                {
                    Transfers = trasnfers,
                    Title = MedicDataLocalization.Get(MedicDataLocalization.Transfers),
                    Description = MedicDataLocalization.Get(MedicDataLocalization.Transfers),
                    Keywords = MedicDataLocalization.Get(MedicDataLocalization.TransfersSummary),
                    Search = search,
                    CurrentPage = page,
                    TotalPages = base.TotalPages((int)search.Length, trasnfersCount),
                    TotalResults = trasnfersCount
                }));
            }
            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 ex;
            }
        }