Skip to content

Commit 4ea0b33

Browse files
committed
REPOSITORY PATTERN
1 parent cf03922 commit 4ea0b33

24 files changed

+984
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Queries", "Queries\Queries.csproj", "{D1776DED-C59A-4F8A-8C31-96EAE15BDF5A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D1776DED-C59A-4F8A-8C31-96EAE15BDF5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D1776DED-C59A-4F8A-8C31-96EAE15BDF5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D1776DED-C59A-4F8A-8C31-96EAE15BDF5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D1776DED-C59A-4F8A-8C31-96EAE15BDF5A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
6+
<startup>
7+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
8+
</startup>
9+
<connectionStrings>
10+
<add name="PlutoContext" connectionString="data source=.\SQLEXPRESS;initial catalog=Pluto_Queries;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
11+
</connectionStrings>
12+
</configuration>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
3+
namespace Queries.Core.Domain
4+
{
5+
public class Author
6+
{
7+
public Author()
8+
{
9+
Courses = new HashSet<Course>();
10+
}
11+
12+
public int Id { get; set; }
13+
14+
public string Name { get; set; }
15+
16+
public virtual ICollection<Course> Courses { get; set; }
17+
}
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
3+
namespace Queries.Core.Domain
4+
{
5+
public class Course
6+
{
7+
public Course()
8+
{
9+
Tags = new HashSet<Tag>();
10+
}
11+
12+
public int Id { get; set; }
13+
14+
public string Name { get; set; }
15+
16+
public string Description { get; set; }
17+
18+
public int Level { get; set; }
19+
20+
public float FullPrice { get; set; }
21+
22+
public virtual Author Author { get; set; }
23+
24+
public int AuthorId { get; set; }
25+
26+
public virtual ICollection<Tag> Tags { get; set; }
27+
28+
public Cover Cover { get; set; }
29+
30+
public bool IsBeginnerCourse
31+
{
32+
get { return Level == 1; }
33+
}
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Queries.Core.Domain
2+
{
3+
public class Cover
4+
{
5+
public int Id { get; set; }
6+
public Course Course { get; set; }
7+
}
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
3+
namespace Queries.Core.Domain
4+
{
5+
public class Tag
6+
{
7+
public Tag()
8+
{
9+
Courses = new HashSet<Course>();
10+
}
11+
12+
public int Id { get; set; }
13+
14+
public string Name { get; set; }
15+
16+
public virtual ICollection<Course> Courses { get; set; }
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Queries.Core.Repositories;
2+
using System;
3+
4+
namespace Queries.Core
5+
{
6+
public interface IUnitOfWork : IDisposable
7+
{
8+
ICourseRepository Courses { get; }
9+
IAuthorRepository Authors { get; }
10+
int Complete();
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Queries.Core.Domain;
2+
3+
namespace Queries.Core.Repositories
4+
{
5+
public interface IAuthorRepository : IRepository<Author>
6+
{
7+
Author GetAuthorWithCourses(int id);
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Queries.Core.Domain;
2+
using System.Collections.Generic;
3+
4+
namespace Queries.Core.Repositories
5+
{
6+
public interface ICourseRepository : IRepository<Course>
7+
{
8+
IEnumerable<Course> GetTopSellingCourses(int count);
9+
IEnumerable<Course> GetCoursesWithAuthors(int pageIndex, int pageSize);
10+
}
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq.Expressions;
4+
5+
namespace Queries.Core.Repositories
6+
{
7+
public interface IRepository<TEntity> where TEntity : class
8+
{
9+
TEntity Get(int id);
10+
IEnumerable<TEntity> GetAll();
11+
IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
12+
13+
// This method was not in the videos, but I thought it would be useful to add.
14+
TEntity SingleOrDefault(Expression<Func<TEntity, bool>> predicate);
15+
16+
void Add(TEntity entity);
17+
void AddRange(IEnumerable<TEntity> entities);
18+
19+
void Remove(TEntity entity);
20+
void RemoveRange(IEnumerable<TEntity> entities);
21+
}
22+
}

0 commit comments

Comments
 (0)