Example #1
0
    public async Task <IViewComponentResult> InvokeAsync(StoreData store)
    {
        var userId          = _userManager.GetUserId(UserClaimsPrincipal);
        var invoiceEntities = await _invoiceRepo.GetInvoices(new InvoiceQuery
        {
            UserId  = userId,
            StoreId = new [] { store.Id },
            Take    = 5
        });

        var invoices = new List <StoreRecentInvoiceViewModel>();

        foreach (var invoice in invoiceEntities)
        {
            var state = invoice.GetInvoiceState();
            invoices.Add(new StoreRecentInvoiceViewModel
            {
                Date           = invoice.InvoiceTime,
                Status         = state,
                InvoiceId      = invoice.Id,
                OrderId        = invoice.Metadata.OrderId ?? string.Empty,
                AmountCurrency = _currencyNameTable.DisplayFormatCurrency(invoice.Price, invoice.Currency),
            });
        }
        var vm = new StoreRecentInvoicesViewModel
        {
            Store    = store,
            Invoices = invoices
        };

        return(View(vm));
    }
        public IActionResult RecentInvoices(string storeId, string cryptoCode)
        {
            var store = HttpContext.GetStoreData();

            if (store == null)
            {
                return(NotFound());
            }

            var vm = new StoreRecentInvoicesViewModel {
                Store = store, CryptoCode = cryptoCode
            };

            return(ViewComponent("StoreRecentInvoices", new { vm }));
        }
    public async Task <IViewComponentResult> InvokeAsync(StoreRecentInvoicesViewModel vm)
    {
        if (vm.Store == null)
        {
            throw new ArgumentNullException(nameof(vm.Store));
        }
        if (vm.CryptoCode == null)
        {
            throw new ArgumentNullException(nameof(vm.CryptoCode));
        }
        if (vm.InitialRendering)
        {
            return(View(vm));
        }

        var userId          = _userManager.GetUserId(UserClaimsPrincipal);
        var invoiceEntities = await _invoiceRepo.GetInvoices(new InvoiceQuery
        {
            UserId          = userId,
            StoreId         = new [] { vm.Store.Id },
            IncludeArchived = false,
            IncludeRefunds  = true,
            Take            = 5
        });

        vm.Invoices = (from invoice in invoiceEntities
                       let state = invoice.GetInvoiceState()
                                   select new StoreRecentInvoiceViewModel
        {
            Date = invoice.InvoiceTime,
            Status = state,
            HasRefund = invoice.Refunds.Any(),
            InvoiceId = invoice.Id,
            OrderId = invoice.Metadata.OrderId ?? string.Empty,
            AmountCurrency = _currencyNameTable.DisplayFormatCurrency(invoice.Price, invoice.Currency),
        }).ToList();

        return(View(vm));
    }