Skip to content

Commit

Permalink
OrderDetails page has been displayed and updated succesfully.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliarmaganuygun committed Oct 21, 2024
1 parent 4bed7f1 commit 8aebe44
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 3 deletions.
45 changes: 43 additions & 2 deletions BulkyWeb/Areas/Admin/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using BookBazaar.DataAccess.Repository.IRepository;
using BookBazaar.Models;
using BookBazaar.Models.ViewModels;
using BookBazaar.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace BookBazaar.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize(Roles = SD.Role_Admin)]
public class OrderController : Controller
{
private readonly IUnitOfWork _unitOfWork;
[BindProperty]
public OrderVM OrderVM { get; set; }

public OrderController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
Expand All @@ -21,6 +23,45 @@ public IActionResult Index()
return View();
}

public IActionResult Details(int orderId)
{
OrderVM = new()
{
OrderHeader = _unitOfWork.OrderHeader.Get(u => u.Id == orderId, includeProperties: "ApplicationUser"),
OrderDetail = _unitOfWork.OrderDetail.GetAll(u => u.OrderHeaderId == orderId, includeProperties: "Product")
};
return View(OrderVM);
}

[HttpPost]
[Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)]
public IActionResult UpdateOrderDetail()
{
var orderHeaderFromDb = _unitOfWork.OrderHeader.Get(u => u.Id == OrderVM.OrderHeader.Id);

orderHeaderFromDb.Name = OrderVM.OrderHeader.Name;
orderHeaderFromDb.PhoneNumber = OrderVM.OrderHeader.PhoneNumber;
orderHeaderFromDb.StreetAddress = OrderVM.OrderHeader.StreetAddress;
orderHeaderFromDb.City = OrderVM.OrderHeader.City;
orderHeaderFromDb.State = OrderVM.OrderHeader.State;
orderHeaderFromDb.PostalCode = OrderVM.OrderHeader.PostalCode;

if (!string.IsNullOrEmpty(OrderVM.OrderHeader.Carrier))
{
orderHeaderFromDb.Carrier = OrderVM.OrderHeader.Carrier;
}
if (!string.IsNullOrEmpty(OrderVM.OrderHeader.TrackingNumber))
{
orderHeaderFromDb.TrackingNumber = OrderVM.OrderHeader.TrackingNumber;
}

_unitOfWork.OrderHeader.Update(orderHeaderFromDb);
_unitOfWork.Save();
TempData["Success"] = "Order details updated successfully";

return RedirectToAction(nameof(Details), new {orderId = orderHeaderFromDb.Id });
}


#region API CALLS
[HttpGet]
Expand Down
243 changes: 243 additions & 0 deletions BulkyWeb/Areas/Admin/Views/Order/Details.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
@model OrderVM

<form method="post">
<input asp-for="OrderHeader.Id" hidden />
<br />
<div class="container">
<div class="card">
<div class="card-header bg-dark text-light ml-0">
<div class="container row">
<div class="col-12 d-none d-md-block col-md-6 pb-1">
<i class="fas fa-shopping-cart"></i> &nbsp; Order Summary
</div>
<div class="col-12 col-md-4 offset-md-2 text-right">
<a asp-action="Index" class="btn btn-outline-info form-control btn-sm">Back to Orders</a>
</div>
</div>
</div>
<div class="card-body">
<div class="container rounded p-2">
<div class="row">
<div class="col-12 col-lg-6 pb-4">
<div class="row">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-primary">PickUp Details:</span>
</h4>
</div>
<div class="row my-1">
<div class="col-3">Name</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.Name" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.Name" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.Name" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Phone</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.PhoneNumber" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.PhoneNumber" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.PhoneNumber" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Address</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.StreetAddress" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.StreetAddress" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.StreetAddress" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">City</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.City" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.City" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.City" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">State</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.State" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.State" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.State" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Zip Code</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.PostalCode" type="text" class="form-control" />
<span asp-validation-for="OrderHeader.PostalCode" class="text-danger"></span>
}
else
{
<input asp-for="OrderHeader.PostalCode" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Email</div>
<div class="col-9">
<input asp-for="OrderHeader.ApplicationUser.Email" readonly type="text" class="form-control" />
</div>
</div>
<div class="row my-1">
<div class="col-3">Order Date</div>
<div class="col-9">
<input value="@Model.OrderHeader.OrderDate.ToShortDateString()" readonly type="text" class="form-control" />
</div>
</div>
<div class="row my-1">
<div class="col-3">Carrier</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.Carrier" type="text" class="form-control" />
}
else
{
<input asp-for="OrderHeader.Carrier" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Tracking</div>
<div class="col-9">
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<input asp-for="OrderHeader.TrackingNumber" type="text" class="form-control" />
}
else
{
<input asp-for="OrderHeader.TrackingNumber" readonly type="text" class="form-control" />
}
</div>
</div>
<div class="row my-1">
<div class="col-3">Shipping Date</div>
<div class="col-9">
<input value="@Model.OrderHeader.ShippingDate.ToShortDateString()" readonly type="text" class="form-control" />
</div>
</div>

@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<div class="row my-1">
<div class="col-3">Session ID</div>
<div class="col-9">
<input asp-for="OrderHeader.SessionId" readonly type="text" class="form-control" />
</div>
</div>
<div class="row my-1">
<div class="col-3">Payment Intent ID</div>
<div class="col-9">
<input asp-for="OrderHeader.PaymentIntentId" readonly type="text" class="form-control" />
</div>
</div>
}

<div class="row my-1">
@if (Model.OrderHeader.SessionId == null)
{
<div class="col-3">Payment Due Date</div>
<div class="col-9">
<input value="@Model.OrderHeader.PaymentDueDate.ToShortDateString()" readonly type="text" class="form-control" />
</div>
}
else
{
<div class="col-3">Payment Date</div>
<div class="col-9">
<input value="@Model.OrderHeader.PaymentDate.ToShortDateString()" readonly type="text" class="form-control" />
</div>
}

</div>
<div class="row my-1">
<div class="col-3">Payment Status</div>
<div class="col-9">
<input asp-for="OrderHeader.PaymentStatus" readonly type="text" class="form-control" />
</div>
</div>
@if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee))
{
<button type="submit" asp-action="UpdateOrderDetail" class="btn btn-warning form-control my-1">Update Order Details</button>
}
</div>
<div class="col-12 col-lg-5 offset-lg-1">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-primary">Order Summary</span>
</h4>
<label class="btn btn-outline-primary form-control my-2">Order Status - @Model.OrderHeader.OrderStatus</label>
<ul class="list-group mb-3">
@foreach (var detail in Model.OrderDetail)
{
<li class="list-group-item d-flex justify-content-between p-2">
<div class="row container">
<div class="col-8">

<h6 class="my-0 text-primary">@detail.Product.Title</h6>
<small class="text-muted">Price : @detail.Product.Price.ToString("c")</small><br />
<small class="text-muted">Quantity : @detail.Count</small>
</div>
<div class="col-4 text-end">
<p class="text-success">@((detail.Price * detail.Count).ToString("c"))</p>
</div>
</div>
</li>
}
<li class="list-group-item bg-primary">
<div class="row container">
<div class="col-6">
<h5 class="text-white">TOTAL </h5>
</div>
<div class="col-6 text-end">
<h5 class="text-white">@Model.OrderHeader.OrderTotal.ToString("c")</h5>
</div>
</div>
</li>
</ul>
<input type="submit" class="btn btn-success form-control my-1" value="Pay Now" />
<input type="submit" class="btn btn-primary form-control my-1" value="Start Processing" />
<input type="submit" class="btn btn-primary form-control my-1" value="Ship Order" />
<input type="submit" class="btn btn-danger form-control my-1" value="Cancel Order" />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
2 changes: 1 addition & 1 deletion BulkyWeb/wwwroot/js/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function loadDataTable(status) {
data: 'id',
"render": function (data) {
return `<div class="w-75 btn-group" role="group">
<a href="/admin/order/details?id=${data}" class="btn btn-primary mx-2"><i class="bi bi-pencil-square"></i></a>
<a href="/admin/order/details?orderId=${data}" class="btn btn-primary mx-2"> <i class="bi bi-pencil-square"></i></a>
</div>`
},
width: '10%'
Expand Down

0 comments on commit 8aebe44

Please sign in to comment.