Skip to content

Commit 0770b25

Browse files
committed
Genre Tree
1 parent acfbec4 commit 0770b25

File tree

10 files changed

+308
-63
lines changed

10 files changed

+308
-63
lines changed

BookStore.DAL.EntityFramework/EfBookRepository.cs

+36-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using BookStore.DAL.Abstract;
55
using BookStore.DO.Entities;
6-
using System.Data.Entity;
6+
using System.Data.Entity;
77

88
namespace BookStore.DAL.EntityFramework
99
{
@@ -16,7 +16,7 @@ public IList<Book> GetBooksByLetter(string letter)
1616
.Include(b => b.BookAuthors)
1717
.Include(b => b.Genres)
1818
.Include(b => b.Tages)
19-
.Where( p => letter == "All" || p.Title.StartsWith(letter) || (num.Contains(p.Title.Substring(0, 1)) && letter == "0-9"))
19+
.Where(p => letter == "All" || p.Title.StartsWith(letter) || (num.Contains(p.Title.Substring(0, 1)) && letter == "0-9"))
2020
.OrderByDescending(b => b.Rating).ToList();
2121
}
2222

@@ -27,12 +27,36 @@ public IList<Book> GetBooksByAuthor(string lastName)
2727

2828
public IList<Book> GetBooksByGenre(string genre)
2929
{
30-
return Context.Books
31-
.Include(b => b.BookAuthors)
32-
.Include(b => b.Genres)
33-
.Include(b => b.Tages)
34-
.Where(p => p.Genres.Any(g => g.Genre_Name == genre))
35-
.OrderByDescending(b => b.Rating).ToList();
30+
Genre curGenre = Context.Genres.FirstOrDefault(x => x.Genre_Name == genre);
31+
GetChilds(curGenre.Genre_ID);
32+
List<Book> books = curGenre.Books.ToList();
33+
if (Childs.Any())
34+
{
35+
foreach (var g in Childs)
36+
{
37+
books.AddRange(g.Books);
38+
}
39+
}
40+
return books;
41+
//return Context.Books
42+
// .Include(b => b.BookAuthors)
43+
// .Include(b => b.Genres)
44+
// .Include(b => b.Tages)
45+
// .Where(p => p.Genres.Any(Childs.Contains))
46+
// .OrderByDescending(b => b.Rating).ToList();
47+
}
48+
private List<Genre> Childs = new List<Genre>();
49+
private void GetChilds(int id)
50+
{
51+
var genres = Context.Genres.Where(x => x.ParentID == id).ToList();
52+
if (genres.Any())
53+
{
54+
foreach (var genre in genres)
55+
{
56+
Childs.Add(genre);
57+
GetChilds(genre.Genre_ID);
58+
}
59+
}
3660
}
3761

3862
public IList<Book> GetBooksByTitle(string title)
@@ -105,7 +129,7 @@ public override void Save(Book obj)
105129
{
106130
if (authorsOld.Any(x => x.Last_Name == author.Last_Name && x.First_Name == author.First_Name))
107131
continue;
108-
var authorForSave = Context.Authors.FirstOrDefault( a => a.Last_Name == author.Last_Name && author.First_Name == a.First_Name);
132+
var authorForSave = Context.Authors.FirstOrDefault(a => a.Last_Name == author.Last_Name && author.First_Name == a.First_Name);
109133
bookForSave.BookAuthors.Add(authorForSave != null
110134
? author
111135
: new Author()
@@ -122,8 +146,8 @@ public override void Save(Book obj)
122146
foreach (var tag in tagsNew)
123147
{
124148
if (tagsOld.Any(x => x.Tag_Name == tag.Tag_Name)) continue;
125-
var tagForSave = Context.Tages.FirstOrDefault( a => a.Tag_Name == tag.Tag_Name);
126-
bookForSave.Tages.Add(tagForSave ?? new Tag{ Tag_Name = tag.Tag_Name });
149+
var tagForSave = Context.Tages.FirstOrDefault(a => a.Tag_Name == tag.Tag_Name);
150+
bookForSave.Tages.Add(tagForSave ?? new Tag { Tag_Name = tag.Tag_Name });
127151
}
128152
}
129153
ICollection<Genre> genresNew = obj.Genres;
@@ -163,7 +187,7 @@ public void AddComment(Comment comment)
163187
Context.Comments.Add(comment);
164188
Context.SaveChanges();
165189
}
166-
190+
167191
public Rate GetRate(int bookId, int userId)
168192
{
169193
return Context.Rates.FirstOrDefault(x => x.User_ID == userId && x.Book.Book_ID == bookId);

BookStore.Domain/Entities/Genre.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public class Genre
1414
[Display(Name = "Жанр")]
1515
public string Genre_Name { get; set; }
1616
public virtual ICollection<Book> Books { get; set; }
17+
public virtual int ParentID { get; set; }
18+
1719
}
1820
}

BookStore/BookStore.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@
374374
<Content Include="Views\Shared\BookHeader.cshtml" />
375375
<Content Include="Views\Book\Comment.cshtml" />
376376
<Content Include="Views\Book\BookRating.cshtml" />
377-
<Content Include="Views\Nav\Genres.cshtml" />
377+
<Content Include="Views\Nav\NodeGenre.cshtml" />
378378
<Content Include="Views\Nav\Authors.cshtml" />
379379
<Content Include="Views\Author\Index.cshtml" />
380380
<Content Include="Views\Book\Fb2Text.cshtml" />
@@ -383,6 +383,7 @@
383383
<SubType>Code</SubType>
384384
</Content>
385385
<Content Include="Views\Book\GetComment.cshtml" />
386+
<Content Include="Views\Nav\LeafGenre.cshtml" />
386387
</ItemGroup>
387388
<ItemGroup>
388389
<Folder Include="App_Data\" />

BookStore/Content/Site1.scss

+54-15
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,13 @@ textarea {
181181
font-size: 14px;
182182
display: inline-block;
183183
margin: 6px;
184-
font-family:Calibri;
185-
color:$color_woodsmoke_approx;
186-
text-decoration:none;
187-
&:hover{
188-
text-decoration:none;
189-
color:$color_storm_dust_approx;
184+
font-family: Calibri;
185+
color: $color_woodsmoke_approx;
186+
text-decoration: none;
187+
188+
&:hover {
189+
text-decoration: none;
190+
color: $color_storm_dust_approx;
190191
}
191192
}
192193
}
@@ -357,8 +358,9 @@ DIV.pager A.selected {
357358
font-family: 'Book Antiqua';
358359
color: $color_storm_dust_approx;
359360
font-size: 14px;
360-
p{
361-
margin:0;
361+
362+
p {
363+
margin: 0;
362364
}
363365
}
364366

@@ -427,6 +429,7 @@ DIV.pager A.selected {
427429
.btn {
428430
margin: 4px;
429431
}
432+
430433
.accordion-toggle {
431434
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
432435
font-size: 16px;
@@ -533,11 +536,47 @@ span.twitter-typeahead {
533536
background-image: -o-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
534537
background-image: linear-gradient(to right, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
535538
}
536-
.statistic{
537-
background-color:whitesmoke;
538-
border-radius:20px;
539-
text-align:center;
540-
canvas{
541-
display:inline-flex;
539+
540+
.statistic {
541+
background-color: whitesmoke;
542+
border-radius: 20px;
543+
text-align: center;
544+
545+
canvas {
546+
display: inline-flex;
547+
}
548+
}
549+
550+
.genre-container {
551+
margin-left: 0;
552+
.leaf {
553+
margin-left: 40px;
554+
}
555+
.collapse-group {
556+
div {
557+
margin-left: 15px;
558+
}
559+
560+
.collapse {
561+
.collapse-group {
562+
.collapse {
563+
margin-left: 20px;
564+
565+
div {
566+
margin-left: 30px;
567+
}
568+
569+
.collapse-group {
570+
.collapse {
571+
margin-left: 20px;
572+
573+
div {
574+
margin-left: 30px;
575+
}
576+
}
577+
}
578+
}
579+
}
580+
}
542581
}
543-
}
582+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using BookStore.Domain.Abstract;
7+
using BookStore.Domain.Entities;
8+
using BookStore.Models;
9+
using System.Data.Entity;
10+
using System.Net;
11+
12+
namespace BookStore.Controllers
13+
{
14+
<<<<<<< HEAD
15+
[Authorize]
16+
=======
17+
18+
[Authorize(Roles = "admin")]
19+
>>>>>>> origin/Build
20+
public class AdminController : Controller
21+
{
22+
//
23+
// GET: /Admin/
24+
public AdminController()
25+
{
26+
27+
}
28+
private IBookRepository repository;
29+
public AdminController(IBookRepository repo)
30+
{
31+
repository = repo;
32+
}
33+
public ViewResult Edit(int bookID, string image_url = null)
34+
{
35+
Book book = repository.Books.Include(x => x.Author).Include(x => x.Tages)
36+
.FirstOrDefault(p => p.Book_ID == bookID);
37+
if (image_url != null) book.Image_url = image_url;
38+
return View(book);
39+
}
40+
41+
public ViewResult AuthorsView(int authorID)
42+
{
43+
return View(repository.Authors.FirstOrDefault(x => x.Author_ID == authorID));
44+
}
45+
public ViewResult Index()
46+
{
47+
return View(repository.Books.Include(x => x.Author).Include(x => x.Tages));
48+
// return View(repository.Books);
49+
}
50+
public ViewResult Create()
51+
{
52+
return View(new Book());
53+
}
54+
[HttpPost]
55+
public ActionResult FindBookImage(string title, string last_name, string first_name, int book_ID)
56+
{
57+
IList<SearchResult> searchResults = SearchResult.getSearch(title + " " + last_name + " " + first_name, "&searchType=image");
58+
ViewData["BookID"] = book_ID;
59+
return PartialView(searchResults.Select(x => x.link));
60+
}
61+
//[HttpPost]
62+
public ActionResult SaveBookImage(string image_url, int bookID)
63+
{
64+
Book book = repository.Books.FirstOrDefault(c => c.Book_ID == bookID);
65+
book.Image_url = image_url;
66+
repository.SaveBook(book);
67+
return RedirectToAction("Edit", new { bookID });
68+
}
69+
public ActionResult FindBookAnnotation(string title, string last_name, string first_name, int bookID)
70+
{
71+
string query = title + " " + last_name + " " + first_name+" "+"litres";
72+
var list = SearchResult.getSearch(query).Select(x => x);
73+
string liveUrl = SearchResult.getSearch(query).FirstOrDefault(x => x.link.Contains("livelib")).link;
74+
//string liveUrl1 = SearchResult.getSearch(query).FirstOrDefault(x => x.link.Contains("mybook")).link;
75+
//var liveUrl2 = SearchResult.getSearch(query).FirstOrDefault(x => x.link.Contains("litres"));
76+
//string liveUrl3 = SearchResult.getSearch(query).FirstOrDefault(x => x.link.Contains("aldebaran")).link;
77+
List<string> links=new List<string>();
78+
List<string> libraries=new List<string>(){"livelib","loveread","litres", "mybook","aldebaran","wikipedia","knizhnik","imhonet"};
79+
80+
foreach (string result in SearchResult.getSearch(query).Select(l=>l.link))
81+
{
82+
if(libraries.Any(result.Contains)){
83+
links.Add(result);
84+
}
85+
}
86+
Book book = repository.Books.FirstOrDefault(x => x.Book_ID == bookID);
87+
book.Annotation = HttpUtility.HtmlDecode(SearchResult.GetInnerText(liveUrl));
88+
repository.SaveBook(book);
89+
return RedirectToAction("Edit", new { bookID });
90+
}
91+
92+
[HttpPost]
93+
public ActionResult Create(Book book)
94+
{
95+
if (ModelState.IsValid)
96+
{
97+
Author author = repository.Authors.FirstOrDefault(x => x.Last_Name == book.Author.Last_Name && x.First_Name == book.Author.First_Name);
98+
if (author == null)
99+
{
100+
author = new Author() { Last_Name = book.Author.Last_Name, First_Name = book.Author.First_Name, Middle_Name = book.Author.Middle_Name };
101+
}
102+
103+
book.Author = author;
104+
ICollection<Tag> list = repository.GetTags(book);
105+
book.Tages = list;
106+
107+
repository.SaveBook(book);
108+
TempData["message"] = string.Format("{0} has been saved", book.Title);
109+
return RedirectToAction("Edit", new { bookID = book.Book_ID });
110+
}
111+
else
112+
{
113+
// there is something wrong with the data values
114+
return View(book);
115+
}
116+
}
117+
118+
[HttpPost]
119+
public ActionResult Edit(Book book)
120+
{
121+
if (ModelState.IsValid)
122+
{
123+
repository.SaveBook(book);
124+
TempData["message"] = string.Format("{0} has been saved", book.Title);
125+
return RedirectToAction("Index");
126+
}
127+
else
128+
{
129+
// there is something wrong with the data values
130+
return View(book);
131+
}
132+
}
133+
134+
[HttpPost]
135+
public ActionResult Delete(int bookId)
136+
{
137+
Book deletedBook = repository.DeleteBook(bookId);
138+
if (deletedBook != null)
139+
{
140+
TempData["message"] = string.Format("{0} was deleted", deletedBook.Title);
141+
}
142+
return RedirectToAction("Index");
143+
}
144+
145+
146+
}
147+
}

0 commit comments

Comments
 (0)