Skip to content

Commit b4373a6

Browse files
committed
Changing database
1 parent b72d052 commit b4373a6

25 files changed

+317
-195
lines changed

Diff for: BookStore.DAL/Abstract/IAuthorRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace BookStore.DAL.Abstract
99
{
10-
interface IAuthorRepository:IStoreRepository<Author>
10+
public interface IAuthorRepository:IStoreRepository<Author>
1111
{
12-
12+
Author GetByName(string last_name, string first_name);
1313
}
1414
}

Diff for: BookStore.DAL/Abstract/IRoleRepository.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using BookStore.DO.Entities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace BookStore.DAL.Abstract
9+
{
10+
public interface IRoleRepository:IStoreRepository<Role>
11+
{
12+
}
13+
}

Diff for: BookStore.DAL/Abstract/IUserRepository.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public interface IUserRepository : IStoreRepository<User>
1313
IQueryable<Book> GetWishedBooks(int userID);
1414
IQueryable<Book> GetRatedBooks(int userID);
1515
IQueryable<Author> GetFavAuthors(int userID);
16-
IQueryable<Role> GetRoles(int userID);
16+
ICollection<Role> GetRoles(int userID);
1717
IQueryable<Comment> GetComment(int userID);
18+
User GetUserByEmail(string email);
1819
void RateBook(Book book);
1920
void WishBook(Book book);
2021
void AddComment(Book book);

Diff for: BookStore.DAL/BookStore.DAL.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@
5050
<Compile Include="Abstract\IAuthorRepository.cs" />
5151
<Compile Include="Abstract\IBookRepository.cs" />
5252
<Compile Include="Abstract\IGenreRepository.cs" />
53+
<Compile Include="Abstract\IRoleRepository.cs" />
5354
<Compile Include="Abstract\IStoreRepository.cs" />
5455
<Compile Include="Abstract\IUserRepository.cs" />
56+
<Compile Include="Concrete\EFAuthorRepository.cs" />
5557
<Compile Include="Concrete\EFBookRepository.cs" />
58+
<Compile Include="Concrete\EFRoleRepository.cs" />
5659
<Compile Include="Concrete\EFStoreRepository.cs" />
5760
<Compile Include="Concrete\EFDbContext.cs" />
5861
<Compile Include="Concrete\EFGenreRepository.cs" />
62+
<Compile Include="Concrete\EFUserRepository.cs" />
5963
<Compile Include="Migrations\Configuration.cs" />
6064
<Compile Include="Properties\AssemblyInfo.cs" />
6165
</ItemGroup>

Diff for: BookStore.DAL/Concrete/EFAuthorRepository.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using BookStore.DAL.Abstract;
2+
using BookStore.DO.Entities;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Data.Entity;
9+
10+
namespace BookStore.DAL.Concrete
11+
{
12+
public class EFAuthorRepository:EFStoreRepository<Author>,IAuthorRepository
13+
{
14+
public Author GetByName(string last_name, string first_name)
15+
{
16+
return context.Authors.FirstOrDefault(a => a.First_Name == first_name && a.Last_Name == last_name);
17+
}
18+
public override IQueryable<Author> GetAll()
19+
{
20+
return context.Authors.Include(b=>b.Books);
21+
}
22+
}
23+
}

Diff for: BookStore.DAL/Concrete/EFBookRepository.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ public class EFBookRepository : EFStoreRepository<Book>, IBookRepository
1414
public IQueryable<Book> GetBooksByLetter(string letter)
1515
{
1616
var num = Enumerable.Range(0, 10).Select(i => i.ToString());
17-
return context.Books.Include(b=>b.Authors).Include(b=>b.Genre).Include(b=>b.Tages)
17+
return context.Books.Include(b=>b.Authors).Include(b=>b.Genres).Include(b=>b.Tages)
1818
.Where(p => letter == "All"
1919
|| p.Title.StartsWith(letter)
20-
|| (num.Contains(p.Title.Substring(0, 1)) && letter == "0-9"))
21-
.OrderBy(b => b.Rating);
20+
|| (num.Contains(p.Title.Substring(0, 1)) && letter == "0-9"));
2221
}
2322

2423
public IQueryable<Book> GetBooksByAuthor(string last_name)
@@ -28,9 +27,8 @@ public IQueryable<Book> GetBooksByAuthor(string last_name)
2827

2928
public IQueryable<Book> GetBooksByGenre(string genre)
3029
{
31-
return context.Books.Include(b => b.Authors).Include(b => b.Genre).Include(b => b.Tages)
32-
.Where(p => genre == null || p.Genre.Genre_Name == genre)
33-
.OrderBy(p => p.Rating);
30+
return context.Books.Include(b => b.Authors).Include(b => b.Genres).Include(b => b.Tages)
31+
.Where(p => genre == null || p.Genres.Any(g=>g.Genre_Name==genre));
3432
}
3533

3634
public IQueryable<Book> GetBooksByTitle(string title)
@@ -41,9 +39,8 @@ public IQueryable<Book> GetBooksByTitle(string title)
4139

4240
public IQueryable<Book> GetBooksByTag(int tagID)
4341
{
44-
return context.Books.Include(b => b.Authors).Include(b => b.Genre).Include(b => b.Tages)
45-
.Where(b => b.Tages.Any(t => t.Tag_ID == tagID))
46-
.OrderBy(p => p.Rating);
42+
return context.Books.Include(b => b.Authors).Include(b => b.Genres).Include(b => b.Tages)
43+
.Where(b => b.Tages.Any(t => t.Tag_ID == tagID));
4744
}
4845

4946
public IQueryable<Comment> GetComment(Comment comment)
@@ -53,11 +50,11 @@ public IQueryable<Comment> GetComment(Comment comment)
5350

5451
public override IQueryable<Book> GetAll()
5552
{
56-
return context.Books.Include(a => a.Authors).Include(a => a.Genre).Include(a => a.Tages);
53+
return context.Books.Include(a => a.Authors).Include(a => a.Genres).Include(a => a.Tages);
5754
}
5855
public override Book GetByID(int ID)
5956
{
60-
return context.Books.Include(a => a.Authors).Include(a => a.Genre).Include(a => a.Tages).FirstOrDefault(b => b.Book_ID == ID);
57+
return context.Books.Include(a => a.Authors).Include(a => a.Genres).Include(a => a.Tages).FirstOrDefault(b => b.Book_ID == ID);
6158
}
6259
}
6360
}

Diff for: BookStore.DAL/Concrete/EFDbContext.cs

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
namespace BookStore.DAL
1111
{
12-
public class EFDbContext: DbContext
12+
public class EFDbContext : DbContext
1313
{
14-
public EFDbContext() : base() {
14+
public EFDbContext()
15+
: base()
16+
{
1517
//this.Configuration.LazyLoadingEnabled = false;
1618
}
1719
public DbSet<Book> Books { get; set; }
@@ -21,6 +23,7 @@ public EFDbContext() : base() {
2123
public DbSet<Rate> Rates { get; set; }
2224
public DbSet<Role> Roles { get; set; }
2325
public DbSet<Genre> Genres { get; set; }
26+
public DbSet<Comment> Comments { get; set; }
2427
//protected override void OnModelCreating(DbModelBuilder modelBuilder)
2528
//{
2629
// //modelBuilder.Entity<Book>().HasRequired(x => x.Author).WithMany(x=>x.Books).HasForeignKey(x=>x.AuthorID);
@@ -29,18 +32,19 @@ public EFDbContext() : base() {
2932
//}
3033
protected override void OnModelCreating(DbModelBuilder modelBuilder)
3134
{
32-
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
35+
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
3336
modelBuilder.Entity<User>()
3437
.HasMany(c => c.ReccomendedBooks).WithMany(i => i.ReccomendedUsers)
3538
.Map(t => t.MapLeftKey("User_ID")
36-
.MapRightKey("Book_ID")
37-
.ToTable("Reccomenation"));
39+
.MapRightKey("Book_ID")
40+
.ToTable("Reccomenation"));
3841
modelBuilder.Entity<User>()
3942
.HasMany(c => c.WishedBooks).WithMany(i => i.WishedUsers)
4043
.Map(t => t.MapLeftKey("User_ID")
41-
.MapRightKey("Book_ID")
42-
.ToTable("Wish"));
43-
//modelBuilder.Entity<User>().HasRequired(p => p.Role).WithMany(b => b.Users).HasForeignKey(p => p.Role_ID);
44-
}
44+
.MapRightKey("Book_ID")
45+
.ToTable("Wish"));
46+
modelBuilder.Entity<Book>().HasKey(b => b.Book_ID);
47+
modelBuilder.Entity<Tag>().HasKey(b => b.Tag_ID);
48+
}
4549
}
4650
}

Diff for: BookStore.DAL/Concrete/EFRoleRepository.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using BookStore.DAL.Abstract;
2+
using BookStore.DO.Entities;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Data.Entity;
9+
10+
namespace BookStore.DAL.Concrete
11+
{
12+
public class EFRoleRepository:EFStoreRepository<Role>, IRoleRepository
13+
{
14+
public override IQueryable<Role> GetAll()
15+
{
16+
return context.Roles.Include(r=>r.Users);
17+
}
18+
public override void Save(Role obj)
19+
{
20+
context.Roles.Add(obj);
21+
context.SaveChanges();
22+
}
23+
}
24+
}

Diff for: BookStore.DAL/Concrete/EFUserRepository.cs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using BookStore.DAL.Abstract;
2+
using BookStore.DO.Entities;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Data.Entity;
9+
10+
namespace BookStore.DAL.Concrete
11+
{
12+
public class EFUserRepository:EFStoreRepository<User>,IUserRepository
13+
{
14+
public IQueryable<Book> GetReccomendedBooks(int userID)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public IQueryable<Book> GetWishedBooks(int userID)
20+
{
21+
throw new NotImplementedException();
22+
}
23+
24+
public IQueryable<Book> GetRatedBooks(int userID)
25+
{
26+
throw new NotImplementedException();
27+
}
28+
29+
public IQueryable<Author> GetFavAuthors(int userID)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
34+
public ICollection<Role> GetRoles(int userID)
35+
{
36+
return context.Users.FirstOrDefault(u => u.User_ID == userID).Roles;
37+
}
38+
39+
public IQueryable<Comment> GetComment(int userID)
40+
{
41+
throw new NotImplementedException();
42+
}
43+
44+
public User GetUserByEmail(string email)
45+
{
46+
return context.Users.Include(e=>e.Roles).FirstOrDefault(e => e.Email == email);
47+
}
48+
49+
public void RateBook(Book book)
50+
{
51+
throw new NotImplementedException();
52+
}
53+
54+
public void WishBook(Book book)
55+
{
56+
throw new NotImplementedException();
57+
}
58+
59+
public void AddComment(Book book)
60+
{
61+
throw new NotImplementedException();
62+
}
63+
64+
public void LikeAuthor(Author author)
65+
{
66+
throw new NotImplementedException();
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)