-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathIndex.cshtml.cs
39 lines (33 loc) · 1.37 KB
/
Index.cshtml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AspnetRunBasics.Repositories;
using AspnetRunBasics.Repositories.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace AspnetRunBasics.Pages
{
public class IndexModel : PageModel
{
private readonly IProductRepository _productRepository;
private readonly ICartRepository _cartRepository;
public IndexModel(IProductRepository productRepository, ICartRepository cartRepository)
{
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
_cartRepository = cartRepository ?? throw new ArgumentNullException(nameof(cartRepository));
}
public IEnumerable<Entities.Product> ProductList { get; set; } = new List<Entities.Product>();
public async Task<IActionResult> OnGetAsync()
{
ProductList = await _productRepository.GetProducts();
return Page();
}
public async Task<IActionResult> OnPostAddToCartAsync(int productId)
{
//if (!User.Identity.IsAuthenticated)
// return RedirectToPage("./Account/Login", new { area = "Identity" });
await _cartRepository.AddItem("test", productId);
return RedirectToPage("Cart");
}
}
}