Skip to content

Commit bd20696

Browse files
adding button favorite author
1 parent d072f00 commit bd20696

File tree

14 files changed

+101
-412
lines changed

14 files changed

+101
-412
lines changed

BookStore.BLL.RepositoryService/UserService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace BookStore.BLL.RepositoryService
1111
public class UserService:StoreService<User>,IUserService
1212
{
1313
[Inject] readonly IUserRepository _repository;
14+
1415
public UserService(IUserRepository repository)
1516
: base(repository)
1617
{
@@ -57,9 +58,9 @@ public void AddComment(Book book)
5758
throw new NotImplementedException();
5859
}
5960

60-
public void LikeAuthor(Author author)
61+
public void LikeAuthor(int authorId, int userId)
6162
{
62-
throw new NotImplementedException();
63+
_repository.LikeAuthor(userId, authorId);
6364
}
6465

6566

BookStore.DAL.EntityFramework/EfAuthorRepository.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public override void Save(Author auth)
4949
authStore.Biography = auth.Biography;
5050
authStore.Image_url = auth.Image_url;
5151

52-
ICollection<User> userNew = auth.FavotiteUsers;
53-
ICollection<User> userOld = authStore.FavotiteUsers;
52+
ICollection<User> userNew = auth.FavoriteUsers;
53+
ICollection<User> userOld = authStore.FavoriteUsers;
5454
if (userNew != null)
5555
{
5656
foreach (var user in userNew)
5757
{
5858
if (userOld.Any(x => x.User_ID == user.User_ID)) continue;
5959
var userForSave = Context.Users.FirstOrDefault(a => a.User_ID == user.User_ID);
60-
authStore.FavotiteUsers.Add(userForSave ?? new User() { User_ID = user.User_ID });
60+
authStore.FavoriteUsers.Add(userForSave ?? new User() { User_ID = user.User_ID });
6161
}
6262
}
6363

BookStore.DAL.EntityFramework/EfUserRepository.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ public void AddComment(Book book)
7171
throw new NotImplementedException();
7272
}
7373

74-
public void LikeAuthor(Author author)
74+
public void LikeAuthor(int authorId, int userId)
7575
{
76-
throw new NotImplementedException();
76+
Author auth = Context.Authors.FirstOrDefault(a => a.Author_ID==authorId);
77+
User user = Context.Users.FirstOrDefault(a => a.User_ID == userId);
78+
if (!auth.FavoriteUsers.Contains(user))
79+
{
80+
auth.FavoriteUsers.Add(user);
81+
}
82+
else
83+
{
84+
auth.FavoriteUsers.Remove(user);
85+
}
86+
Context.SaveChanges();
7787
}
7888

7989
public override void Create(User obj)

BookStore.DAL/Abstract/IUserRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IUserRepository : IStoreRepository<User>
1919
void RateBook(float rate,int userId, int bookId,bool isSuggestion);
2020
void WishBook(Book book);
2121
void AddComment(Book book);
22-
void LikeAuthor(Author author);
22+
void LikeAuthor(int authorId, int userId);
2323
void Resuggest();
2424
}
2525
}

BookStore.DLL/Abstract/IUserService.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public interface IUserService:IStoreService<User>
1919
void RateBook(float rate,int userId, int bookId,bool isSuggestion);
2020
void WishBook(Book book);
2121
void AddComment(Book book);
22-
void LikeAuthor(Author author);
23-
22+
void LikeAuthor(int authorId, int userId);
2423
}
2524
}

BookStore.Domain/Entities/Author.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public Author()
3232
[Display(Name = "Рейтинг")]
3333
public int Rating { get; set; }
3434
public virtual ICollection<Book> Books { get; set; }
35-
public virtual ICollection<User> FavotiteUsers { get; set; }
35+
public virtual ICollection<User> FavoriteUsers { get; set; }
3636
}
3737
}

BookStore/Content/Site1.scss

+10
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,13 @@ span.twitter-typeahead {
467467
font-family: 'Trebuchet MS', 'Lucida Sans Unicode';
468468
}
469469
}
470+
.love
471+
{
472+
font: icon,normal;
473+
margin-top: 10px;
474+
}
475+
.love_author {
476+
vertical-align: middle;
477+
content: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAFzUkdCAK7OHOkAA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J2VnQKXgH8L8AcarFp5PRk4bgAAAABJRU5ErkJggg=='); /*Images/love_author.png*/
478+
}
479+

BookStore/Controllers/UserController.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ public class UserController : Controller
1818
{
1919
private readonly IUserService _userService;
2020
private readonly IBookService _bookService;
21+
private readonly IAuthorService _authorService;
22+
2123
private readonly log4net.ILog logger =
2224
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
23-
public UserController(IUserService userService, IBookService bookService)
25+
public UserController(IUserService userService, IBookService bookService, IAuthorService authorService)
2426
{
2527
_userService = userService;
2628
_bookService = bookService;
29+
_authorService = authorService;
2730
}
2831

2932
public ActionResult Profile(string user)
@@ -59,6 +62,13 @@ public ActionResult FileUpload(HttpPostedFileBase file)
5962
// after successfully uploading redirect the user
6063
return RedirectToAction("List", "Book");
6164
}
65+
66+
[HttpPost]
67+
public int FavoriteAuthor(int userId, int authorId)
68+
{
69+
_userService.LikeAuthor(authorId,userId);
70+
return _authorService.GetById(authorId).FavoriteUsers.Count;
71+
}
6272
public float SclarProduct(float[] u_f, float[] v_f, int dim)
6373
{
6474
float res = 0;

BookStore/Scripts/rate.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
$(document).ready(function () {
22
$('.typeahead').mouseenter(GetNames);
33
$('#input-23').on('rating.change', Rate);
4+
$('.love_author').onclick(LoveAuthor);
45
});
56

7+
function LoveAuthor(userId,authorId) {
8+
debugger;
9+
$.ajax({
10+
type: "POST",
11+
url: "/User/FavoriteAuthor",
12+
data: { userId: userId,authorId:authorId },
13+
success: function (data) {
14+
debugger;
15+
$('#love-this-author').text(data);
16+
}
17+
});
18+
};
19+
620
function GetNames() {
721
$('.typeahead').unbind('mouseenter mouseleave');
822
$.ajax({

BookStore/Views/Author/Index.cshtml

+44-38
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<div class="container-fluid">
2525
<div class="row">
2626
@*<div class="col-md-1 rateBook">
27-
<p class="glyphicon glyphicon-heart-empty " aria-hidden="true">@book.RateValue</p>
28-
</div>*@
27+
<p class="glyphicon glyphicon-heart-empty " aria-hidden="true">@book.RateValue</p>
28+
</div>*@
2929
<div class="col-md-11">
3030
@{ Html.RenderPartial("BookHeader", book); }
3131
</div>
@@ -36,47 +36,53 @@
3636
</div>
3737
</div>
3838
</div>
39-
@*<div class="comments">
40-
<div class="detailBox">
41-
<div class="actionBox">
42-
<ul class="commentList">
43-
@foreach (var comment in @Model.Comments)
44-
{
45-
<li>
46-
<div class="commenterImage">
47-
48-
<a href="@Url.RouteUrl(new {action = "Profile", controller = "User", user = Session["UserName"]})">
49-
<img src="@Url.Content(Session["UserImage"].ToString())"/>
50-
</a>
51-
</div>
52-
<div class="commentText">
53-
<p class="">@comment.Context</p> <span class="date sub-text">@comment.DataCreate</span>
54-
</div>
55-
</li>
56-
}
57-
</ul>
58-
<div class="form-group form-input">
59-
@{
60-
if (Session["UserId"] != null)
39+
@*<div class="comments">
40+
<div class="detailBox">
41+
<div class="actionBox">
42+
<ul class="commentList">
43+
@foreach (var comment in @Model.Comments)
6144
{
62-
Html.RenderAction("AddComment", "Book", new {bookId = @Model.Book_ID});
45+
<li>
46+
<div class="commenterImage">
47+
48+
<a href="@Url.RouteUrl(new {action = "Profile", controller = "User", user = Session["UserName"]})">
49+
<img src="@Url.Content(Session["UserImage"].ToString())"/>
50+
</a>
51+
</div>
52+
<div class="commentText">
53+
<p class="">@comment.Context</p> <span class="date sub-text">@comment.DataCreate</span>
54+
</div>
55+
</li>
6356
}
64-
}
57+
</ul>
58+
<div class="form-group form-input">
59+
@{
60+
if (Session["UserId"] != null)
61+
{
62+
Html.RenderAction("AddComment", "Book", new {bookId = @Model.Book_ID});
63+
}
64+
}
65+
</div>
6566
</div>
6667
</div>
67-
</div>
68-
</div>*@
68+
</div>*@
6969
</div>
70-
<div class="col-md-2 col-lg-2 image">
71-
@if (Model.Image_url != null)
72-
{
73-
<img src="@Url.Content(Model.Image_url)" class="img-thumbnail" alt="images" />
74-
}
75-
else
76-
{
77-
<img src="@Url.Content("~/Content/Images/authorImg0.png")" class="img-thumbnail" alt="images" />
78-
}
70+
@{ int userId = (int) @Session["UserId"];}
71+
<div class="col-md-2 col-lg-2 ">
72+
<div class="image">
73+
@if (Model.Image_url != null)
74+
{
75+
<img src="@Url.Content(Model.Image_url)" class="img-thumbnail" alt="images" />
76+
}
77+
else
78+
{
79+
<img src="@Url.Content("~/Content/Images/authorImg0.png")" class="img-thumbnail" alt="images" />
80+
}
81+
</div>
82+
<div class="love">
83+
<span class="love_author" onclick="LoveAuthor(@userId, @Model.Author_ID )" data-toggle="tooltip" data-placement="left" title="Автор понравился"></span>
84+
<label id="love-this-author">@Model.FavoriteUsers.Count</label>
85+
</div>
7986
</div>
8087
</div>
8188
</div>
82-

BookStore/Web.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</log4net>
4040

4141
<connectionStrings>
42-
<add name="EfDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Book; Integrated Security=True" providerName="System.Data.SqlClient" />
42+
<add name="EfDbContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=BookStore; Integrated Security=True" providerName="System.Data.SqlClient" />
4343
</connectionStrings>
4444
<appSettings>
4545
<add key="webpages:Version" value="3.0.0.0" />

0 commit comments

Comments
 (0)