Skip to content

Commit ea45ba4

Browse files
committed
Dashboard/Order
1 parent 5f6e01a commit ea45ba4

File tree

15 files changed

+283
-20
lines changed

15 files changed

+283
-20
lines changed

.vs/BookStore/v16/.suo

5 KB
Binary file not shown.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using BookStore.Data;
6+
using BookStore.Data.Interface;
7+
using BookStore.Data.Repositories;
8+
using BookStore.Models;
9+
using Microsoft.AspNetCore.Authorization;
10+
using Microsoft.AspNetCore.Http;
11+
using Microsoft.AspNetCore.Mvc;
12+
13+
namespace BookStore.Areas.Dashboard.Controllers
14+
{
15+
[Authorize]
16+
[Area("Dashboard")]
17+
public class OrderController : Controller
18+
{
19+
//private readonly BookStoreContext storeContext;
20+
private readonly IOrderRepository orderRepo;
21+
22+
public OrderController(IOrderRepository orderRepo)
23+
{
24+
this.orderRepo = orderRepo;
25+
}
26+
27+
// GET: OrderController
28+
public ActionResult Index()
29+
{
30+
return View();
31+
}
32+
33+
public ActionResult GetData()
34+
{
35+
List<Order> OrderLists = orderRepo.Orders.ToList();
36+
return Json(new { data = OrderLists});
37+
}
38+
39+
// GET: OrderController/Details/5
40+
public ActionResult Details(int id)
41+
{
42+
var orderDetails = orderRepo.GetOrderById(id);
43+
return View(orderDetails);
44+
}
45+
46+
// GET: OrderController/Create
47+
public ActionResult Create()
48+
{
49+
return View();
50+
}
51+
52+
// POST: OrderController/Create
53+
[HttpPost]
54+
[ValidateAntiForgeryToken]
55+
public ActionResult Create(IFormCollection collection)
56+
{
57+
try
58+
{
59+
return RedirectToAction(nameof(Index));
60+
}
61+
catch
62+
{
63+
return View();
64+
}
65+
}
66+
67+
// GET: OrderController/Edit/5
68+
public ActionResult Edit(int id)
69+
{
70+
return View();
71+
}
72+
73+
// POST: OrderController/Edit/5
74+
[HttpPost]
75+
[ValidateAntiForgeryToken]
76+
public ActionResult Edit(int id, IFormCollection collection)
77+
{
78+
try
79+
{
80+
return RedirectToAction(nameof(Index));
81+
}
82+
catch
83+
{
84+
return View();
85+
}
86+
}
87+
88+
// GET: OrderController/Delete/5
89+
public ActionResult Delete(int id)
90+
{
91+
return View();
92+
}
93+
94+
// POST: OrderController/Delete/5
95+
[HttpPost]
96+
[ValidateAntiForgeryToken]
97+
public ActionResult Delete(int id, IFormCollection collection)
98+
{
99+
try
100+
{
101+
return RedirectToAction(nameof(Index));
102+
}
103+
catch
104+
{
105+
return View();
106+
}
107+
}
108+
}
109+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@model BookStore.Models.Order
2+
@{
3+
ViewData["Title"] = "Details";
4+
}
5+
6+
@foreach (var item in Model.OrderLines)
7+
{
8+
<h1>@item.Price x @item.Amount => @Model.OrderTotal</h1>
9+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
@{
3+
ViewData["Title"] = "Index";
4+
Layout = "_Layout";
5+
}
6+
7+
<div class="row">
8+
<div class="col-md-12">
9+
<div class="tile">
10+
<div class="tile-title-w-btn">
11+
<h3 class="title">Order Lists</h3>
12+
@*<p><a class="btn btn-primary icon-btn" href="#"><i class="fa fa-plus"></i>Add Item </a></p>*@
13+
</div>
14+
<div class="tile-body">
15+
<div class="table-responsive">
16+
<table class="table table-bordered" id="sampleTable">
17+
<thead>
18+
<tr>
19+
<th>#</th>
20+
<th>Customer Name(full)</th>
21+
<th>Address Detail</th>
22+
<th>Contact Info</th>
23+
<th>Order Total</th>
24+
<th>Order Date</th>
25+
<th>Buttons</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
@*@foreach (var item in Model)
30+
{
31+
<tr>
32+
<td>@item.Id</td>
33+
<td>@item.Name</td>
34+
<td>@item.Author</td>
35+
<td>@item.Details</td>
36+
<td>@item.Price</td>
37+
<td>@item.Category.Name</td>
38+
<td>
39+
<div class="btn-group-sm" style="width:90px">
40+
<a class="btn btn-primary" onclick="PopupForm('Dashboard/Book/_AddOrEdit/@item.Id')" href="#"><i class="fa fa-lg fa-edit"></i></a>
41+
<a class="btn btn-danger" href="#" onclick=""><i class="fa fa-lg fa-trash"></i></a>
42+
</div>
43+
</td>
44+
</tr>
45+
}*@
46+
</tbody>
47+
</table>
48+
</div>
49+
</div>
50+
</div>
51+
</div>
52+
</div>
53+
54+
@section scripts{
55+
<script src="~/js/plugins/jquery-ui.js"></script>
56+
<script type="text/javascript" src="~/js/plugins/sweetalert.min.js"></script>
57+
<!-- Data table plugin-->
58+
<script type="text/javascript" src="~/js/plugins/jquery.dataTables.min.js"></script>
59+
<script type="text/javascript" src="~/js/plugins/dataTables.bootstrap.min.js"></script>
60+
<script type="text/javascript" src="~/js/plugins/bootstrap-notify.min.js"></script>
61+
62+
<script type="text/javascript">
63+
var dataTable /*= $('#sampleTable').DataTable()*/;
64+
65+
$(document).ready(function () {
66+
dataTable = $('#sampleTable').DataTable({
67+
processing: true,
68+
//serverSide: true,
69+
ajax: {
70+
url: "/Dashboard/Order/GetData",
71+
type: "Get",
72+
contentType: "application/Json",
73+
dataType: "Json"
74+
},
75+
columns: [
76+
{ data: "id" },
77+
{
78+
data: "firstName",
79+
render: function (data, type, row) {
80+
return data + " " + row.lastName;
81+
}
82+
},
83+
{
84+
data: "address",
85+
render: function (data, type, row) {
86+
return data + " " + row.state + "-" + row.zipCode+", "+ row.country;
87+
}
88+
},
89+
{
90+
data: "email",
91+
render: function (data, type, row) {
92+
return "Email: <a href='mailto:" + data + "'>" + data + "</a></br>" +
93+
"Phone: <a href='tel:" + row.phoneNumber + "'>" + row.phoneNumber+"</a>";
94+
}
95+
},
96+
{ data: "orderTotal" },
97+
{ data: "orderedPlaced" },
98+
{
99+
data: "id",
100+
"render": function (data) {
101+
return "<div class='btn-group' style='width:90px'>"
102+
+ "<a class='btn btn-danger' href='/Dashboard/Order/Details/" + data + "'><i class='fa fa-lg fa-reply'></i>View</a></div>";
103+
},
104+
orderable: false,
105+
searchable: false
106+
}
107+
],
108+
language: {
109+
infoEmpty: "No records found!",
110+
emptyTable: "No Data Found! Please Click <b>Add New</b> to add.",
111+
},
112+
113+
});
114+
});
115+
</script>
116+
117+
}

BookStore/Areas/Dashboard/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,7 @@
132132
</ul>
133133
</li>
134134
<li><a class="app-menu__item" asp-controller="Home" asp-action="GuestMessages"><i class="app-menu__icon fa fa-pie-chart"></i><span class="app-menu__label">Messages</span></a></li>
135-
<li class="treeview">
136-
<a class="app-menu__item" href="#" data-toggle="treeview"><i class="app-menu__icon fa fa-edit"></i><span class="app-menu__label">Forms</span><i class="treeview-indicator fa fa-angle-right"></i></a>
137-
<ul class="treeview-menu">
138-
<li><a class="treeview-item" href="form-components.html"><i class="icon fa fa-circle-o"></i> Form Components</a></li>
139-
<li><a class="treeview-item" href="form-custom.html"><i class="icon fa fa-circle-o"></i> Custom Components</a></li>
140-
<li><a class="treeview-item" href="form-samples.html"><i class="icon fa fa-circle-o"></i> Form Samples</a></li>
141-
<li><a class="treeview-item" href="form-notifications.html"><i class="icon fa fa-circle-o"></i> Form Notifications</a></li>
142-
</ul>
143-
</li>
144-
<li><a class="app-menu__item" href="docs.html"><i class="app-menu__icon fa fa-file-code-o"></i><span class="app-menu__label">Docs</span></a></li>
135+
<li><a class="app-menu__item" asp-controller="Order" asp-action=""><i class="app-menu__icon fa fa-file-code-o"></i><span class="app-menu__label">Order Lists</span></a></li>
145136
</ul>
146137
</aside>
147138

BookStore/BookStore.csproj.user

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
4+
<Controller_SelectedScaffolderID>MvcControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
55
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
66
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
77
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
8-
<WebStackScaffolding_IsPartialViewSelected>True</WebStackScaffolding_IsPartialViewSelected>
8+
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
99
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>False</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
1010
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
1111
<WebStackScaffolding_ViewDialogWidth>600</WebStackScaffolding_ViewDialogWidth>
1212
<WebStackScaffolding_DependencyDialogWidth>600</WebStackScaffolding_DependencyDialogWidth>
1313
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
1414
<ShowAllFiles>false</ShowAllFiles>
1515
<WebStackScaffolding_LayoutPageFile>_Layout</WebStackScaffolding_LayoutPageFile>
16-
<View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
16+
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
1717
<View_SelectedScaffolderCategoryPath>root/View</View_SelectedScaffolderCategoryPath>
1818
</PropertyGroup>
1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

BookStore/Controllers/OrderController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public IActionResult Checkout()
3232
ModelState.AddModelError("", "Cart is Empty. Add some Books first.");
3333
}
3434

35-
OrderViewModel orderView = new OrderViewModel
35+
CheckoutViewModel orderView = new CheckoutViewModel
3636
{
3737
ShopingCart = _shopingCart,
3838
ShopingCartTotal = _shopingCart.GetShopingCartTotal()

BookStore/Data/Interface/IOrderRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace BookStore.Data.Interface
88
{
99
public interface IOrderRepository
1010
{
11+
IEnumerable<Order> Orders { get; }
12+
IEnumerable<OrderDetail> GetOrderDetails(int orderId);
13+
Order GetOrderById(int id);
14+
1115
void CreateOrder(Order order);
1216
}
1317
}

BookStore/Data/Repositories/OrderRepository.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BookStore.Data.Interface;
22
using BookStore.Models;
3+
using Microsoft.EntityFrameworkCore;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -17,8 +18,12 @@ public OrderRepository(BookStoreContext storeContext,ShopingCart shopingCart)
1718
_shopingCart = shopingCart;
1819
}
1920

21+
public IEnumerable<Order> Orders => _storeContext.Orders;
22+
2023
public void CreateOrder(Order order)
2124
{
25+
if (order == null) throw new NullReferenceException();
26+
2227
order.OrderedPlaced = DateTime.Now;
2328
_storeContext.Orders.Add(order); //Add Order
2429

@@ -37,5 +42,20 @@ public void CreateOrder(Order order)
3742
_storeContext.SaveChanges();
3843
}
3944

45+
public Order GetOrderById(int id)
46+
{
47+
var order = _storeContext.Orders
48+
.Include(f => f.OrderLines)
49+
.Where(f => f.Id == id)
50+
.FirstOrDefault();
51+
return order;
52+
}
53+
54+
public IEnumerable<OrderDetail> GetOrderDetails(int orderId)
55+
{
56+
var orderDetails = _storeContext.OrderDetails
57+
.Where(f => f.OrderId == orderId);
58+
return orderDetails;
59+
}
4060
}
4161
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace BookStore.Models.ViewModels
7+
{
8+
public class CheckoutViewModel
9+
{
10+
public Order Order { get; set; }
11+
//public ShopingCartViewModel ShopingCartVM { get; set; }
12+
public ShopingCart ShopingCart { get; set; }
13+
public decimal ShopingCartTotal { get; set; }
14+
}
15+
}

0 commit comments

Comments
 (0)