Skip to content

Commit 5f6e01a

Browse files
committed
create order
1 parent dd28b21 commit 5f6e01a

File tree

13 files changed

+139
-84
lines changed

13 files changed

+139
-84
lines changed

.vs/BookStore/v16/.suo

-18 KB
Binary file not shown.

BookStore/Controllers/OrderController.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using BookStore.Data.Interface;
66
using BookStore.Models;
7+
using BookStore.Models.ViewModels;
78
using Microsoft.AspNetCore.Authorization;
89
using Microsoft.AspNetCore.Mvc;
910

@@ -23,7 +24,20 @@ public OrderController(IOrderRepository orderRepository, ShopingCart shopingCart
2324
//[Authorize]
2425
public IActionResult Checkout()
2526
{
26-
return View();
27+
var items = _shopingCart.GetShopingCartItems();
28+
_shopingCart.ShopingCartItems = items;
29+
30+
if (_shopingCart.ShopingCartItems.Count == 0)
31+
{
32+
ModelState.AddModelError("", "Cart is Empty. Add some Books first.");
33+
}
34+
35+
OrderViewModel orderView = new OrderViewModel
36+
{
37+
ShopingCart = _shopingCart,
38+
ShopingCartTotal = _shopingCart.GetShopingCartTotal()
39+
};
40+
return View(orderView);
2741
}
2842

2943
[HttpPost]
@@ -33,6 +47,8 @@ public IActionResult CheckOut(Order order)
3347
var items = _shopingCart.GetShopingCartItems();
3448
_shopingCart.ShopingCartItems = items;
3549

50+
if (order == null) throw new NullReferenceException();
51+
3652
if (_shopingCart.ShopingCartItems.Count == 0)
3753
{
3854
ModelState.AddModelError("", "Cart is Empty. Add some Books first.");
@@ -45,9 +61,9 @@ public IActionResult CheckOut(Order order)
4561
_orderRepository.CreateOrder(order);
4662
_shopingCart.ClearCart();
4763

48-
return RedirectToAction("CheckoutComplete");
64+
return Json(new { success = true, message = "Saved Successfull" });
4965
}
50-
return View();
66+
return Json(new { success = false, message = "Saved Unsuccessfull" });
5167
}
5268

5369
public IActionResult CheckoutComplete()

BookStore/Controllers/ShopingCartController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public RedirectToActionResult RemoveFromShopingCart(int bookId)
5959

6060
public RedirectToActionResult ClearCart()
6161
{
62+
if(_shopingCart.ShopingCartItems != null)
63+
_shopingCart.ShopingCartItems = _shopingCart.GetShopingCartItems();
6264
_shopingCart.ClearCart();
6365

6466
return RedirectToAction("Index");
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 OrderViewModel
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+
}

BookStore/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void ConfigureServices(IServiceCollection services)
6464

6565
services.AddSession(options =>
6666
{
67-
options.IdleTimeout = TimeSpan.FromSeconds(30);
67+
options.IdleTimeout = TimeSpan.FromSeconds(120);
6868
options.Cookie.HttpOnly = true;
6969
options.Cookie.IsEssential = true;
7070
});

BookStore/Views/Gallery/_BookGallery.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
</div>
1414
<div class="product__content content--center">
15-
<h4><a href="single-product.html">@item.Name</a></h4>
15+
<h4><a asp-controller="Gallery" asp-action="Book" asp-route-id="@item.Id">@item.Name</a></h4>
1616
<ul class="prize d-flex">
1717
<li>@item.Price</li>
1818
<li class="old_prize">@item.PriceOffer</li>
@@ -21,7 +21,7 @@
2121
<div class="actions_inner">
2222
<ul class="add_to_links">
2323
<li><a class="cart" asp-action="AddToShopingCart" asp-controller="ShopingCart" asp-route-bookId="@item.Id"><i class="bi bi-shopping-bag4"></i></a></li>
24-
<li><a class="wishlist" href="wishlist.html"><i class="bi bi-shopping-cart-full"></i></a></li>
24+
<li><a class="wishlist" href="#"><i class="bi bi-shopping-cart-full"></i></a></li>
2525
<li><a class="compare" href="#"><i class="bi bi-heart-beat"></i></a></li>
2626
<li><a data-toggle="modal" onclick="quickView(@item.Id)" title="Quick View" class="quickview modal-view detail-link" href="#productmodal"><i class="bi bi-search"></i></a></li>
2727
</ul>

BookStore/Views/Home/About.cshtml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
@*<h3>@ViewData["Message"]</h3>*@
66

77
<!-- Start Bradcaump area -->
8-
<div class="ht__bradcaump__area" style="background-image:url('../images/about/big-img/1.jpg');background-color:teal;background-position:center -5em;background-size:cover">
8+
<div class="ht__bradcaump__area"
9+
style="
10+
background: url('../images/about/big-img/1.jpg');
11+
background-color: gray;
12+
background-position: center center;
13+
background-size: cover;
14+
background-blend-mode: soft-light;
15+
">
916
<div class="container">
1017
<div class="row">
1118
<div class="col-lg-12">

BookStore/Views/Order/Checkout.cshtml

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@model BookStore.Models.Order
1+
@model OrderViewModel
22
@{
33
ViewData["Title"] = "Checkout";
44
Layout = "_LayoutN";
@@ -25,7 +25,7 @@
2525
<!-- Start Checkout Area -->
2626
<section class="wn__checkout__area section-padding--lg bg__white">
2727
<div class="container">
28-
<div class="row">
28+
@*<div class="row">
2929
<div class="col-lg-12">
3030
<div class="wn_checkout_wrap">
3131
<div class="checkout_info">
@@ -69,50 +69,53 @@
6969
</div>
7070
</div>
7171
</div>
72-
</div>
72+
</div>*@
7373
<div class="row">
7474
<div class="col-lg-6 col-12">
7575
<div class="customer_details">
7676
<h3>Billing details</h3>
7777
<div class="customar__field">
78-
<div class="margin_between">
79-
<div class="input_box space_between">
80-
<label asp-for="FirstName">First name <span>*</span></label>
81-
<input asp-for="FirstName" type="text">
78+
<form id="orderForm">
79+
<div class="margin_between">
80+
<input type="hidden" name="Id" value="0" />
81+
<div class="input_box space_between">
82+
<label asp-for="Order.FirstName">First name <span>*</span></label>
83+
<input name="FirstName" type="text">
84+
</div>
85+
<div class="input_box space_between">
86+
<label asp-for="Order.LastName">last name <span>*</span></label>
87+
<input type="text" name="LastName">
88+
</div>
8289
</div>
83-
<div class="input_box space_between">
84-
<label asp-for="LastName">last name <span>*</span></label>
85-
<input type="text" asp-for="LastName">
90+
<div class="input_box">
91+
<label asp-for="Order.Country">Country <span>*</span></label>
92+
<input type="text" name="Country">
8693
</div>
87-
</div>
88-
<div class="input_box">
89-
<label asp-for="Country">Country <span>*</span></label>
90-
<input type="text" asp-for="Country">
91-
</div>
92-
<div class="input_box">
93-
<label asp-for="Address">Address <span>*</span></label>
94-
<input type="text" asp-for="Address" placeholder="Street address">
95-
</div>
96-
<div class="input_box">
97-
<input type="text" asp-for="State" placeholder="State">
98-
</div>
99-
<div class="input_box">
100-
<label asp-for="ZipCode">Postcode / ZIP <span>*</span></label>
101-
<input type="text" asp-for="ZipCode">
102-
</div>
103-
<div class="margin_between">
104-
<div class="input_box space_between">
105-
<label asp-for="PhoneNumber">Phone <span>*</span></label>
106-
<input type="text" asp-for="PhoneNumber">
94+
<div class="input_box">
95+
<label asp-for="Order.Address">Address <span>*</span></label>
96+
<input type="text" name="Address" placeholder="Street address">
97+
</div>
98+
<div class="input_box">
99+
<input type="text" name="State" placeholder="State">
107100
</div>
101+
<div class="input_box">
102+
<label asp-for="Order.ZipCode">Postcode / ZIP <span>*</span></label>
103+
<input type="text" name="ZipCode">
104+
</div>
105+
<div class="margin_between">
106+
<div class="input_box space_between">
107+
<label asp-for="Order.PhoneNumber">Phone <span>*</span></label>
108+
<input type="text" name="PhoneNumber">
109+
</div>
108110

109-
<div class="input_box space_between">
110-
<label asp-for="Email">Email address <span>*</span></label>
111-
<input type="email" asp-for="Email">
111+
<div class="input_box space_between">
112+
<label asp-for="Order.Email">Email address <span>*</span></label>
113+
<input type="email" name="Email">
114+
</div>
112115
</div>
113-
</div>
116+
</form>
114117
</div>
115-
<div class="create__account">
118+
@*<div class="create__account">
116119
<div class="wn__accountbox">
117120
<input class="input-checkbox" name="createaccount" value="1" type="checkbox">
118121
<span>Create an account ?</span>
@@ -123,6 +126,9 @@
123126
<input type="text" placeholder="password">
124127
</form>
125128
</div>
129+
</div>*@
130+
<div class="create_order">
131+
<button type="button" onclick="SubmitOrder()" class="btn btn-light w--100">Order Now</button>
126132
</div>
127133
</div>
128134
</div>
@@ -134,29 +140,25 @@
134140
<li>Total</li>
135141
</ul>
136142
<ul class="order_product">
137-
<li>Buscipit at magna × 1<span>$48.00</span></li>
138-
<li>Buscipit at magna × 1<span>$48.00</span></li>
139-
<li>Buscipit at magna × 1<span>$48.00</span></li>
140-
<li>Buscipit at magna × 1<span>$48.00</span></li>
143+
@foreach (var item in Model.ShopingCart.ShopingCartItems)
144+
{
145+
<li>@item.Book.Name × @item.Amount<span>$@(item.Amount*item.Book.Price)</span></li>
146+
}
141147
</ul>
142148
<ul class="shipping__method">
143-
<li>Cart Subtotal <span>$48.00</span></li>
149+
<li>Cart Subtotal <span>$@Model.ShopingCartTotal</span></li>
144150
<li>
145151
Shipping
146152
<ul>
147153
<li>
148154
<input name="shipping_method[0]" data-index="0" value="legacy_flat_rate" checked="checked" type="radio">
149-
<label>Flat Rate: $48.00</label>
150-
</li>
151-
<li>
152-
<input name="shipping_method[0]" data-index="0" value="legacy_flat_rate" checked="checked" type="radio">
153-
<label>Flat Rate: $48.00</label>
155+
<label>Flat Rate: $10.00</label>
154156
</li>
155157
</ul>
156158
</li>
157159
</ul>
158160
<ul class="total__amount">
159-
<li>Order Total <span>$223.00</span></li>
161+
<li>Order Total <span>$@(Model.ShopingCartTotal+10)</span></li>
160162
</ul>
161163
</div>
162164
<div id="accordion" class="checkout_accordion mt--30" role="tablist">
@@ -206,4 +208,29 @@
206208
</div>
207209
</div>
208210
</section>
209-
<!-- End Checkout Area -->
211+
<!-- End Checkout Area -->
212+
@section scripts{
213+
214+
<script>
215+
function SubmitOrder() {
216+
var obj = $("#orderForm").serialize();
217+
//var obj = new FormData(document.getElementById("orderForm"));
218+
219+
$.ajax({
220+
type: "post",
221+
url: "/Order/Checkout",
222+
data: obj,
223+
dataType: "json",
224+
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
225+
//processData: false,
226+
success: function (data) {
227+
if (data.success) {
228+
alert(data.message);
229+
} else {
230+
alert(data.message);
231+
}
232+
}
233+
});
234+
}
235+
</script>
236+
}

BookStore/Views/Shared/_LayoutN.cshtml

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
<nav class="mainmenu__nav">
4949
<ul class="meninmenu d-flex justify-content-start">
5050
<li class="drop with--one--item"><a asp-action="Index" asp-controller="Home">Home</a></li>
51-
<li class="drop">
51+
<!--Shop
52+
<li class="drop">
5253
<a href="#">Shop</a>
5354
<div class="megamenu mega03">
5455
<ul class="item item03">
@@ -160,42 +161,29 @@
160161
<div class="col-lg-12 d-none">
161162
<nav class="mobilemenu__nav">
162163
<ul class="meninmenu">
163-
<li><a href="index.html">Home</a></li>
164-
<li>
165-
<a href="#">Pages</a>
166-
<ul>
167-
<li><a href="about.html">About Page</a></li>
168-
<li>
169-
<a href="portfolio.html">Portfolio</a>
170-
<ul>
171-
<li><a href="portfolio.html">Portfolio</a></li>
172-
<li><a href="portfolio-details.html">Portfolio Details</a></li>
173-
</ul>
174-
</li>
175-
<li><a href="my-account.html">My Account</a></li>
176-
<li><a href="cart.html">Cart Page</a></li>
177-
<li><a href="checkout.html">Checkout Page</a></li>
178-
<li><a href="wishlist.html">Wishlist Page</a></li>
179-
<li><a href="error404.html">404 Page</a></li>
180-
<li><a href="faq.html">Faq Page</a></li>
181-
<li><a href="team.html">Team Page</a></li>
182-
</ul>
183-
</li>
164+
<li><a asp-action="Index" asp-controller="Home">Home</a></li>
184165
<li>
185166
<a href="shop-grid.html">Shop</a>
186167
<ul>
187-
<li><a href="shop-grid.html">Shop Grid</a></li>
188-
<li><a href="single-product.html">Single Product</a></li>
168+
<li><a asp-controller="Gallery" asp-action="Index">Books</a></li>
169+
<li><a asp-controller="Gallery" asp-action="Categories">Category Lists</a></li>
189170
</ul>
190171
</li>
191172
<li>
192-
<a href="blog.html">Blog</a>
173+
<a href="#">Help</a>
193174
<ul>
194-
<li><a href="blog.html">Blog Page</a></li>
195-
<li><a href="blog-details.html">Blog Details</a></li>
175+
<li><a asp-controller="Home" asp-action="About">About Us</a></li>
176+
<li><a asp-controller="Home" asp-action="Contact">Contact Us</a></li>
177+
<li>
178+
<a href="https://github.com/madcoderBubt">Portfolio</a>
179+
<ul>
180+
<li><a href="https://madcoderbubt.github.io/MadCoderPersonal/">Personal Site</a></li>
181+
<li><a href="https://www.hackerrank.com/MadCoder_BUBT">HackerRank</a></li>
182+
</ul>
183+
</li>
196184
</ul>
197185
</li>
198-
<li><a href="contact.html">Contact</a></li>
186+
<li><a href="https://shbsovon.blogspot.com">Blog</a></li>
199187
</ul>
200188
</nav>
201189
</div>

BookStore/Views/ShopingCart/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<td class="product-name"><a href="#">@item.Book.Name</a></td>
4949
<td class="product-price"><span class="amount">@item.Book.Price.ToString("c")</span></td>
5050
<td class="product-quantity"><input type="number" value="@item.Amount"></td>
51-
<td class="product-subtotal">@(item.Book.Price * item.Amount).ToString("c")</td>
51+
<td class="product-subtotal">@((item.Book.Price * item.Amount).ToString("c"))</td>
5252
<td class="product-remove"><a asp-action="RemoveFromShopingCart" asp-route-bookId="@item.BookId">X</a></td>
5353
</tr>
5454
}

0 commit comments

Comments
 (0)