Skip to content

Commit dd28b21

Browse files
committed
Shoping Cart update
1 parent 9ec4231 commit dd28b21

File tree

16 files changed

+185
-819
lines changed

16 files changed

+185
-819
lines changed

.vs/BookStore/v16/.suo

37.5 KB
Binary file not shown.

BookStore/BookStore.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
66
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
77
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
8-
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
8+
<WebStackScaffolding_IsPartialViewSelected>True</WebStackScaffolding_IsPartialViewSelected>
99
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>False</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
1010
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
1111
<WebStackScaffolding_ViewDialogWidth>600</WebStackScaffolding_ViewDialogWidth>

BookStore/Controllers/GalleryController.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public GalleryController(IBookRepository bookRepository, ICategoryRepository cat
2323
}
2424

2525
//GET: Book
26-
public ActionResult Index(string c, string fb, int pn = 1)
26+
//c => Category | fb => FilterBook | pn => pageNumber
27+
public ActionResult Index(string c, string fb, string src, int pn = 1)
2728
{
2829
int totalPages = 6;
2930
int lengthItem;
@@ -36,6 +37,7 @@ public ActionResult Index(string c, string fb, int pn = 1)
3637

3738
string _currentCategory = string.Empty;
3839

40+
//getting books by catergories
3941
if (string.IsNullOrEmpty(c) || c == "All Books")
4042
{
4143
books = _bookRepository.Books;
@@ -48,6 +50,14 @@ public ActionResult Index(string c, string fb, int pn = 1)
4850
_currentCategory = c;
4951
}
5052

53+
//searching for specific book
54+
if (!string.IsNullOrEmpty(src))
55+
{
56+
books1 = books.Where(f => f.Name.Contains(src, StringComparison.InvariantCultureIgnoreCase));
57+
books = books1;
58+
}
59+
60+
//filtering books by price range
5161
if (!string.IsNullOrEmpty(fb))
5262
{
5363
string[] s = fb.Split('-');
@@ -74,7 +84,9 @@ public ActionResult Index(string c, string fb, int pn = 1)
7484
currentPage = pn,
7585
totalPages = Convert.ToInt32(Math.Ceiling(lengthItem / (double)totalPages)),
7686
pageSize = totalPages,
77-
Categories = _categoryRepository.Categories.OrderBy(s => s.Name)
87+
Categories = _categoryRepository.Categories
88+
.Take(15)
89+
.OrderBy(s => s.Name)
7890
};
7991

8092
return View(galleryView);
@@ -86,7 +98,19 @@ public ActionResult Book(int id)
8698

8799
var book = _bookRepository.GetBookById(id);
88100

89-
return View(book);
101+
BookViewModel bookView = new BookViewModel
102+
{
103+
Book = book,
104+
RelatedBooks = _bookRepository.Books
105+
.Where(f => f.CategoryId == book.CategoryId)
106+
.Take(3)
107+
.OrderBy(s=>s.Name),
108+
Categories = _categoryRepository.Categories
109+
.Take(15)
110+
.OrderBy(s => s.Name)
111+
};
112+
113+
return View(bookView);
90114
}
91115
}
92116
}

BookStore/Controllers/ShopingCartController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public ViewResult Index()
3737
}
3838

3939
// GET: ShopingCart/AddToShopingCart
40-
public RedirectToActionResult AddToShopingCart(int bookId)
40+
public RedirectToActionResult AddToShopingCart(int bookId, int qty = 1)
4141
{
4242
var selectedBook = _bookRepository.Books.FirstOrDefault(b => b.Id == bookId);
4343
if (selectedBook != null)
4444
{
45-
_shopingCart.AddToShopingCart(selectedBook, 1);
45+
_shopingCart.AddToShopingCart(selectedBook, qty);
4646
}
4747
return RedirectToAction("Book", "Gallery", new { id = bookId });
4848
}

BookStore/Models/ShopingCart.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static ShopingCart GetShopingCart(IServiceProvider service)
3333
return new ShopingCart(context) { ShopingCartId = cartId };
3434
}
3535

36-
public void AddToShopingCart(Book book,int amount)
36+
public void AddToShopingCart(Book book,int qty)
3737
{
3838
var shopingCartItem = _dbContext.ShopingCartItems.SingleOrDefault(
3939
s => s.Book.Id == book.Id && s.ShopingCartId == ShopingCartId);
@@ -43,7 +43,7 @@ public void AddToShopingCart(Book book,int amount)
4343
shopingCartItem = new ShopingCartItem
4444
{
4545
ShopingCartId = ShopingCartId,
46-
Amount = 1,
46+
Amount = qty,
4747
Book = book
4848
};
4949
_dbContext.ShopingCartItems.Add(shopingCartItem);
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 BookViewModel
9+
{
10+
public Book Book { get; set; }
11+
public IEnumerable<Book> RelatedBooks { get; set; }
12+
public IEnumerable<Category> Categories { get; set; }
13+
14+
}
15+
}

0 commit comments

Comments
 (0)