Skip to content

Commit b1fa14a

Browse files
committed
Merge remote-tracking branch 'origin/YandexSearch' into YandexSearch
Conflicts: BookStore/Views/Shared/_Layout.cshtml
2 parents 6d79aa9 + c5fe7f9 commit b1fa14a

27 files changed

+246
-593
lines changed

Diff for: BookStore.BLL.RepositoryService/obj/Debug/BookStore.BLL.RepositoryService.csproj.FileListAbsolute.txt

-23
This file was deleted.

Diff for: BookStore.DAL.EntityFramework/EfBookRepository.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ public override void Save(Book obj)
119119
public override void Create(Book obj)
120120
{
121121
ICollection<Author> authors = obj.BookAuthors;
122-
obj.BookAuthors =new List<Author>();
122+
obj.BookAuthors = new List<Author>();
123123
foreach (var author in authors)
124124
{
125-
Author authorForSave = Context.Authors.FirstOrDefault(a => a.Last_Name == author.Last_Name && author.First_Name == a.First_Name) ??
125+
Author authorForSave = Context
126+
.Authors
127+
.FirstOrDefault(a => a.Last_Name == author.Last_Name && author.First_Name == a.First_Name) ??
126128
new Author() { Last_Name = author.Last_Name, First_Name = author.First_Name, Middle_Name = author.Middle_Name };
129+
127130
obj.BookAuthors.Add(authorForSave);
128131
}
129132
Context.Books.Add(obj);

Diff for: BookStore.DAL.EntityFramework/obj/Debug/BookStore.DAL.EntityFramework.csproj.FileListAbsolute.txt

-24
This file was deleted.

Diff for: BookStore.DAL/obj/Debug/BookStore.DAL.csproj.FileListAbsolute.txt

-16
This file was deleted.

Diff for: BookStore.Domain/Entities/Author.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace BookStore.DO.Entities
99
{
1010
public class Author
1111
{
12+
public Author()
13+
{
14+
Books = new List<Book>();
15+
}
16+
1217
[Key]
1318
[ScaffoldColumn(false)]
1419
public int Author_ID { get; set; }

Diff for: BookStore.Domain/obj/Debug/BookStore.DO.csproj.FileListAbsolute.txt

-27
This file was deleted.

Diff for: BookStore/App_Start/BundleConfig.cs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static void RegisterBundles(BundleCollection bundles)
2626
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
2727
"~/Scripts/bootstrap*"));
2828

29+
bundles.Add(new ScriptBundle("~/bundles/common").Include(
30+
"~/Scripts/common.js"));
31+
2932
bundles.Add(new StyleBundle("~/Content/css")
3033
.Include("~/Content/site1.css") /* не перепутайте порядок */
3134
.Include("~/Content/site.css")

Diff for: BookStore/BookStore.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
<None Include="Scripts\jquery-1.9.1.intellisense.js" />
323323
<Content Include="Scripts\bootstrap.js" />
324324
<Content Include="Scripts\bootstrap.min.js" />
325+
<Content Include="Scripts\common.js" />
325326
<Content Include="Scripts\demo.js" />
326327
<Content Include="Scripts\jquery-1.9.1.js" />
327328
<Content Include="Scripts\jquery-1.9.1.min.js" />
@@ -390,6 +391,8 @@
390391
<Content Include="Views\Admin\EditorTemplates\Tag.cshtml" />
391392
<Content Include="Views\Admin\EditorTemplates\Author.cshtml" />
392393
<Content Include="Views\Admin\EditorTemplates\Genre.cshtml" />
394+
<Content Include="Views\Account\Ajax.cshtml" />
395+
<Content Include="Views\Account\_Ok.cshtml" />
393396
<Content Include="Views\User\Index.cshtml" />
394397
<Content Include="Views\Book\BookDetails.cshtml" />
395398
<Content Include="Views\Shared\BookHeader.cshtml" />
@@ -471,4 +474,4 @@
471474
</Target>
472475
<Target Name="AfterBuild">
473476
</Target> -->
474-
</Project>
477+
</Project>

Diff for: BookStore/Content/Images/451Farenheit.jpg

-26 KB
Binary file not shown.

Diff for: BookStore/Content/Images/ForWhomTheBellTolls.jpg

-53.1 KB
Binary file not shown.

Diff for: BookStore/Content/Images/MartinEden.jpg

-29.3 KB
Binary file not shown.

Diff for: BookStore/Content/Images/TheHobbit.jpg

-15.6 KB
Binary file not shown.

Diff for: BookStore/Controllers/AccountController.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public AccountController(IUserService user_service, IRoleService role_service)
2222
_userService = user_service;
2323
_roleService = role_service;
2424
}
25-
25+
2626
public ViewResult Login()
2727
{
2828
return View();
@@ -40,7 +40,7 @@ public ActionResult Login(LoginViewModel model, string returnUrl)
4040
}
4141
ModelState.AddModelError("", "Incorrect username or password");
4242
}
43-
return View();//model
43+
return View();
4444
}
4545

4646
public ActionResult LogOff()
@@ -75,12 +75,34 @@ public ActionResult UserLogin()
7575
{
7676
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
7777
if (authCookie != null)
78-
{
78+
{
7979
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
8080
return PartialView(Membership.GetUser(ticket.Name, false));
8181
}
8282
return PartialView(Membership.GetUser());
8383
}
84+
85+
[HttpGet]
86+
public ActionResult Ajax()
87+
{
88+
return PartialView(new LoginViewModel());
89+
}
90+
91+
[HttpPost]
92+
public ActionResult Ajax(LoginViewModel model)
93+
{
94+
if (ModelState.IsValid)
95+
{
96+
if (Membership.ValidateUser(model.UserName, model.Password))
97+
{
98+
Roles.IsUserInRole(model.UserName, "admin");
99+
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
100+
return View("_Ok");
101+
}
102+
ModelState.AddModelError("", "Incorrect username or password");
103+
}
104+
return View(model);
105+
}
84106
}
85107

86108
}

Diff for: BookStore/Controllers/AdminController.cs

+41-12
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,35 @@
66
using BookStore.DO.Entities;
77
using BookStore.Models;
88
using BookStore.DLL.Abstract;
9+
using System.Net;
10+
using System.IO;
11+
using System.Web.Hosting;
912

1013
namespace BookStore.Controllers
1114
{
1215

1316
[Authorize(Roles = "admin")]
1417
public class AdminController : Controller
1518
{
16-
//
17-
// GET: /Admin/
1819
public AdminController()
1920
{
2021

2122
}
23+
2224
private readonly IBookService _bookService;
2325
private readonly IGenreService _genreService;
2426
private IAuthorService _authorService;
27+
2528
public AdminController(IBookService repo, IGenreService genreService, IAuthorService authorService)
2629
{
2730
_bookService = repo;
2831
_genreService = genreService;
2932
_authorService = authorService;
3033
}
31-
public ViewResult Edit(int bookId, string imageUrl = null)
34+
35+
public ViewResult Edit(int bookId)
3236
{
3337
Book book = _bookService.GetById(bookId);
34-
if (imageUrl != null) book.Image_url = imageUrl;
3538
List<SelectListItem> genreList = new List<SelectListItem>();
3639
foreach (Genre genre in _genreService.Genres)
3740
{
@@ -44,29 +47,58 @@ public ViewResult Edit(int bookId, string imageUrl = null)
4447
ViewBag.Genres = genreList;
4548
return View(book);
4649
}
50+
4751
public ViewResult Index()
4852
{
4953
return View(_bookService.GetAll());
5054
}
55+
5156
public ViewResult Create()
5257
{
5358
return View(new Book { BookAuthors = new List<Author> { new Author() }, Genres = new List<Genre> { new Genre()} });
5459
}
60+
5561
[HttpPost]
5662
public ActionResult FindBookImage(string title, string lastName, string firstName, int bookId)
5763
{
5864
IList<SearchResult> searchResults = SearchResult.getSearch(title + " " + lastName + " " + firstName, "&searchType=image");
5965
ViewData["BookID"] = bookId;
6066
return PartialView(searchResults.Select(x => x.link));
6167
}
62-
//[HttpPost]
68+
6369
public ActionResult SaveBookImage(string imageUrl, int bookId)
6470
{
71+
var dbUrl = copyImageToHost(imageUrl, bookId);
72+
6573
Book book = _bookService.Books.FirstOrDefault(c => c.Book_ID == bookId);
66-
book.Image_url = imageUrl;
74+
book.Image_url = dbUrl;
6775
_bookService.Save(book);
6876
return RedirectToAction("Edit", new { bookID = bookId });
6977
}
78+
79+
private string copyImageToHost(string imageUrl, int bookId)
80+
{
81+
var httpWebRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
82+
httpWebRequest.AllowAutoRedirect = false;
83+
var ex = imageUrl.Split('.');
84+
var imgName = "imgBook" + bookId.ToString() + '.' + ex.Last();
85+
var dbUrl = "~/Content/Images/" + imgName;
86+
var svUrl = Server.MapPath("~/Content/Images/");
87+
var path = string.Format(svUrl + imgName);
88+
89+
using (var fileStream = System.IO.File.Create(path))
90+
{
91+
using (var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
92+
{
93+
using (var stream = httpWebResponse.GetResponseStream())
94+
{
95+
stream.CopyTo(fileStream);
96+
}
97+
}
98+
}
99+
return dbUrl;
100+
}
101+
70102
[HttpPost]
71103
public ActionResult SaveAnnotation(string annotation, int bookId)
72104
{
@@ -75,6 +107,7 @@ public ActionResult SaveAnnotation(string annotation, int bookId)
75107
_bookService.Save(book);
76108
return RedirectToAction("Edit", new { bookID = bookId });
77109
}
110+
78111
[HttpPost]
79112
public ActionResult FindBookAnnotation(string title, string lastName, string firstName, int bookId)
80113
{
@@ -83,32 +116,28 @@ public ActionResult FindBookAnnotation(string title, string lastName, string fir
83116
ViewData["BookID"] = bookId;
84117
return PartialView(SearchResult.GetInnerText(links));
85118
}
119+
86120
[HttpPost]
87121
public ActionResult Create(Book book)
88122
{
89123
if (ModelState.IsValid)
90124
{
91125
_bookService.Create(book);
92-
//book.Authors = authors;
93-
//.Save(book);
94126
TempData["message"] = string.Format("{0} has been saved", book.Title);
95127
return RedirectToAction("Edit", new { bookID = book.Book_ID });
96128
}
97-
// there is something wrong with the data values
98129
return View(book);
99130
}
131+
100132
[HttpPost]
101133
public ActionResult Edit(Book book)
102134
{
103135
if (ModelState.IsValid)
104136
{
105-
//Genre genre = genreService.Genres.FirstOrDefault(g => g.Genre_Name == book.Genre.Genre_Name);
106-
//book.Genre = genre;
107137
_bookService.Save(book);
108138
TempData["message"] = string.Format("{0} has been saved", book.Title);
109139
return RedirectToAction("Index");
110140
}
111-
// there is something wrong with the data values
112141
return View(book);
113142
}
114143

0 commit comments

Comments
 (0)