Browse Source

Added ProductDetail page

pull/118/head
malik masis 4 years ago
parent
commit
6e7c40a347
  1. 65
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/ProductDetail.cshtml
  2. 38
      apps/public-web/src/EShopOnAbp.PublicWeb/Pages/ProductDetail.cshtml.cs

65
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/ProductDetail.cshtml

@ -0,0 +1,65 @@
@page "{id:guid}"
@using EShopOnAbp.Localization
@using Microsoft.Extensions.Localization
@using System.Globalization
@using Microsoft.Extensions.Options
@using Volo.Abp.Http.Client
@model EShopOnAbp.PublicWeb.Pages.ProductDetailModel
@inject IStringLocalizer<EShopOnAbpResource> L
@inject IOptions<AbpRemoteServiceOptions> options
@{
string pageHeader = Model.Product.Name;
}
@section styles{
<abp-style src="/Pages/index.css" />
}
@section scripts {
<abp-script src="/client-proxies/basket-proxy.js" />
<abp-script src="/Pages/index.js" />
}
@if (Model.HasRemoteServiceError)
{
pageHeader = L["CatalogServiceNotAvailable"];
}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-6 col-md-6 col-sm-6 ">
<h3 class="pt-5 pb-4 text-center">@pageHeader</h3>
<div class="product-list">
@{
var product = Model.Product;
var productPrice = product.Price.ToString("C", new CultureInfo("en-US"));
string productImage = !product.ImageName.IsNullOrEmpty() ? $"{options.Value.RemoteServices.Default.BaseUrl}product-images/{product.ImageName}" : $"{options.Value.RemoteServices.Default.BaseUrl}product-images/@product.ImageName";
string buyText = L["Index:AddToBasket"];
<div class="product-list-item" data-product-id="@product.Id.ToString()">
<div class="col">
<div class="product-info-box">
<h6>@product.Name</h6>
<em class="d-block text-muted">@product.Code - @L["StockCount"]: @product.StockCount</em>
</div>
</div>
<img src="@productImage" />
<div class="row mt-5 ">
@if (product.StockCount > 0)
{
<abp-button class="add-basket-button" button-type="Warning" text="@buyText" data-product-id="@product.Id.ToString()"></abp-button>
}
else
{
<abp-button disabled="true" class="add-basket-button" button-type="Warning" text="@L["Index:OutOfStock"]" />
}
<div class="info-section col" style="text-align: center">
<span class="product-price">@productPrice</span>
</div>
</div>
</div>
}
</div>
</div>
</div>
</div>

38
apps/public-web/src/EShopOnAbp.PublicWeb/Pages/ProductDetail.cshtml.cs

@ -0,0 +1,38 @@
using EShopOnAbp.CatalogService.Products;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
namespace EShopOnAbp.PublicWeb.Pages
{
public class ProductDetailModel : AbpPageModel
{
[BindProperty(SupportsGet = true)]
public int OrderNo { get; set; }
public ProductDto Product { get; private set; }
public bool HasRemoteServiceError { get; set; } = false;
private readonly IPublicProductAppService _productAppService;
public ProductDetailModel(IPublicProductAppService productAppService)
{
_productAppService = productAppService;
}
public async Task OnGet(Guid id)
{
try
{
Product = await _productAppService.GetAsync(id);
}
catch (Exception e)
{
Product = new ProductDto();
HasRemoteServiceError = true;
Console.WriteLine(e);
}
}
}
}
Loading…
Cancel
Save