Checking tenantId in MVC to only display customisations if tenantId equals 1

This commit is contained in:
espent1004 2020-02-01 19:52:31 +01:00
parent 0365b52e66
commit 48e795fda2
4 changed files with 62 additions and 41 deletions

View File

@ -81,8 +81,11 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
public async Task<IActionResult> Detail(string orderId) public async Task<IActionResult> Detail(string orderId)
{ {
var user = _appUserParser.Parse(HttpContext.User); var user = _appUserParser.Parse(HttpContext.User);
if (user.TenantId == 1)
{
Boolean RFIDScanned = await AllGoodsRFIDScanned(orderId); Boolean RFIDScanned = await AllGoodsRFIDScanned(orderId);
ViewData["RFIDScanned"] = RFIDScanned; ViewData["RFIDScanned"] = RFIDScanned;
}
var order = await _orderSvc.GetOrder(user, orderId); var order = await _orderSvc.GetOrder(user, orderId);
return View(order); return View(order);
@ -91,11 +94,17 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
public async Task<IActionResult> Index(Order item) public async Task<IActionResult> Index(Order item)
{ {
var user = _appUserParser.Parse(HttpContext.User); var user = _appUserParser.Parse(HttpContext.User);
var vm = await _orderSvc.GetMyOrders(user); var vm = await _orderSvc.GetMyOrders(user);
if (user.TenantId == 1)
{
List<ShippingInformation> shippingInformation = GetShippingInfo(vm); List<ShippingInformation> shippingInformation = GetShippingInfo(vm);
_logger.LogInformation("----- Shipping info{@ShippingInformation}", shippingInformation); _logger.LogInformation("----- Shipping info{@ShippingInformation}", shippingInformation);
ViewData["ShippingInfo"] = shippingInformation; ViewData["ShippingInfo"] = shippingInformation;
}
return View(vm); return View(vm);
} }
@ -148,7 +157,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e);
_logger.LogInformation("----- Exception{@e} -----", e); _logger.LogInformation("----- Exception{@e} -----", e);
} }
} }

View File

@ -28,5 +28,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.ViewModels
public string Name { get; set; } public string Name { get; set; }
[Required] [Required]
public string LastName { get; set; } public string LastName { get; set; }
[Required]
public int TenantId { get; set; }
} }
} }

View File

@ -21,7 +21,10 @@
<section class="esh-orders_detail-title col-2">Date</section> <section class="esh-orders_detail-title col-2">Date</section>
<section class="esh-orders_detail-title col-2">Total</section> <section class="esh-orders_detail-title col-2">Total</section>
<section class="esh-orders_detail-title col-2">Status</section> <section class="esh-orders_detail-title col-2">Status</section>
@if (rfidScanned != null)
{
<section class="esh-orders_detail-title col-2">RFID Scanned</section> <section class="esh-orders_detail-title col-2">RFID Scanned</section>
}
</article> </article>
<article class="esh-orders_detail-items row"> <article class="esh-orders_detail-items row">
@ -29,7 +32,10 @@
<section class="esh-orders_detail-item col-2">@Model.OrderNumber</section> <section class="esh-orders_detail-item col-2">@Model.OrderNumber</section>
<section class="esh-orders_detail-item col-2">@Model.Date</section> <section class="esh-orders_detail-item col-2">@Model.Date</section>
<section class="esh-orders_detail-title col-2">@Model.Status</section> <section class="esh-orders_detail-title col-2">@Model.Status</section>
@if (rfidScanned != null)
{
<section class="esh-orders_detail-title col-2">@rfidScanned</section> <section class="esh-orders_detail-title col-2">@rfidScanned</section>
}
</article> </article>
</section> </section>

View File

@ -5,16 +5,17 @@
@{ @{
ViewData["Title"] = "My Orders"; ViewData["Title"] = "My Orders";
var headerList = new List<Header>() { var headerList = new List<Header>()
new Header() { Controller = "Catalog", Text = "Back to catalog" }, {
new Header() { Text = " / " }, new Header() {Controller = "Catalog", Text = "Back to catalog"},
new Header() { Controller = "OrderManagement", Text = "Orders Management" } }; new Header() {Text = " / "},
new Header() {Controller = "OrderManagement", Text = "Orders Management"}
};
var shippingInfo = ViewData["ShippingInfo"] as List<ShippingInformation>; var shippingInfo = ViewData["ShippingInfo"] as List<ShippingInformation>;
} }
<div class="esh-orders"> <div class="esh-orders">
<partial name="_Header" model="headerList" /> <partial name="_Header" model="headerList"/>
<div class="container"> <div class="container">
<article class="esh-orders-titles row"> <article class="esh-orders-titles row">
@ -22,8 +23,11 @@
<section class="esh-orders-title col-2">Date</section> <section class="esh-orders-title col-2">Date</section>
<section class="esh-orders-title col-1">Total</section> <section class="esh-orders-title col-1">Total</section>
<section class="esh-orders-title col-1">Status</section> <section class="esh-orders-title col-1">Status</section>
@if (shippingInfo != null)
{
<section class="esh-orders-title col-2">Shipping date</section> <section class="esh-orders-title col-2">Shipping date</section>
<section class="esh-orders-title col-2">Estimated arrival date</section> <section class="esh-orders-title col-2">Estimated arrival date</section>
}
<section class="esh-orders-title col-2"></section> <section class="esh-orders-title col-2"></section>
</article> </article>
@ -36,13 +40,16 @@
<section class="esh-orders-item col-2">@item.Date.ToShortDateString()</section> <section class="esh-orders-item col-2">@item.Date.ToShortDateString()</section>
<section class="esh-orders-item col-1">$ @Html.DisplayFor(modelItem => item.Total)</section> <section class="esh-orders-item col-1">$ @Html.DisplayFor(modelItem => item.Total)</section>
<section class="esh-orders-item col-1">@Html.DisplayFor(modelItem => item.Status)</section> <section class="esh-orders-item col-1">@Html.DisplayFor(modelItem => item.Status)</section>
@if (shippingInfo != null)
{
<section class="esh-orders-item col-2"> <section class="esh-orders-item col-2">
@for (var i = 0; i < shippingInfo.Count(); i++) @for (var i = 0; i < shippingInfo.Count(); i++)
{ {
var si = shippingInfo[i]; var si = shippingInfo[i];
if (si.OrderNumber.Equals(item.OrderNumber)) if (si.OrderNumber.Equals(item.OrderNumber))
{ {
@si.ShippingTime.ToShortDateString(); @si.ShippingTime.ToShortDateString()
;
break; break;
} }
} }
@ -53,11 +60,13 @@
var si = shippingInfo[i]; var si = shippingInfo[i];
if (si.OrderNumber.Equals(item.OrderNumber)) if (si.OrderNumber.Equals(item.OrderNumber))
{ {
@si.ArrivalTime.ToShortDateString(); @si.ArrivalTime.ToShortDateString()
;
break; break;
} }
} }
</section> </section>
}
<section class="esh-orders-item col-1"> <section class="esh-orders-item col-1">
<a class="esh-orders-link" asp-controller="Order" asp-action="Detail" asp-route-orderId="@item.OrderNumber">Detail</a> <a class="esh-orders-link" asp-controller="Order" asp-action="Detail" asp-route-orderId="@item.OrderNumber">Detail</a>
</section> </section>
@ -72,7 +81,3 @@
} }
</div> </div>
</div> </div>