diff --git a/BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs b/BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs index 237e7c7..c3df5f7 100644 --- a/BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs +++ b/BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs @@ -4,6 +4,7 @@ using BulkyBook.Utility; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Stripe; using System; using System.Collections.Generic; using System.Linq; @@ -39,6 +40,7 @@ public IActionResult Details(int orderId) } [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] [ValidateAntiForgeryToken] public IActionResult UpdateOrderDetail() { @@ -64,6 +66,7 @@ public IActionResult UpdateOrderDetail() } [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] [ValidateAntiForgeryToken] public IActionResult StartProcessing() { @@ -74,6 +77,7 @@ public IActionResult StartProcessing() } [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] [ValidateAntiForgeryToken] public IActionResult ShipOrder() { @@ -82,12 +86,45 @@ public IActionResult ShipOrder() orderHeader.Carrier = OrderVM.OrderHeader.Carrier; orderHeader.OrderStatus = SD.StatusShipped; orderHeader.ShippingDate = DateTime.Now; + if (orderHeader.PaymentStatus == SD.PaymentStatusDelayedPayment) + { + orderHeader.PaymentDueDate = DateTime.Now.AddDays(30); + } _unitOfWork.OrderHeader.Update(orderHeader); _unitOfWork.Save(); TempData["Success"] = "Order Shipped Successfully."; return RedirectToAction("Details", "Order", new { orderId = OrderVM.OrderHeader.Id }); } + [HttpPost] + [Authorize(Roles = SD.Role_Admin + "," + SD.Role_Employee)] + [ValidateAntiForgeryToken] + public IActionResult CancelOrder() + { + var orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, tracked: false); + if (orderHeader.PaymentStatus == SD.PaymentStatusApproved) + { + var options = new RefundCreateOptions + { + Reason = RefundReasons.RequestedByCustomer, + PaymentIntent = orderHeader.PaymentIntentId + }; + + var service = new RefundService(); + Refund refund = service.Create(options); + + _unitOfWork.OrderHeader.UpdateStatus(orderHeader.Id, SD.StatusCancelled, SD.StatusRefunded); + } + else + { + _unitOfWork.OrderHeader.UpdateStatus(orderHeader.Id, SD.StatusCancelled, SD.StatusCancelled); + } + _unitOfWork.Save(); + + TempData["Success"] = "Order Cancelled Successfully."; + return RedirectToAction("Details", "Order", new { orderId = OrderVM.OrderHeader.Id }); + } + #region API CALLS [HttpGet] public IActionResult GetAll(string status) diff --git a/BulkyBookWeb/Areas/Admin/Views/Order/Details.cshtml b/BulkyBookWeb/Areas/Admin/Views/Order/Details.cshtml index 83838ab..eac78fe 100644 --- a/BulkyBookWeb/Areas/Admin/Views/Order/Details.cshtml +++ b/BulkyBookWeb/Areas/Admin/Views/Order/Details.cshtml @@ -248,10 +248,10 @@ { } - @if (Model.OrderHeader.OrderStatus != SD.StatusRefunded || + @if (Model.OrderHeader.OrderStatus != SD.StatusRefunded && Model.OrderHeader.OrderStatus != SD.StatusCancelled) { - + } }