-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepository.cs
More file actions
75 lines (68 loc) · 1.97 KB
/
Repository.cs
File metadata and controls
75 lines (68 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace $rootnamespace$.$modelname$
{
/// <summary>
/// $modelname$Repository
/// </summary>
public class $modelname$Repository : I$modelname$Repository
{
private readonly ILogger<$modelname$Repository> logger;
private readonly DbContext dbContext;
/// <summary>
///
/// </summary>
/// <param name="dbContext"></param>
/// <param name="logger"></param>
public $modelname$Repository(DbContext dbContext, ILogger<$modelname$Repository> logger)
{
this.dbContext = dbContext;
this.logger = logger;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<ICollection<$modelname$>> GetAll()
{
return await dbContext.$modelname$.ToListAsync();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<$modelname$> GetById(int id)
{
return await dbContext.$modelname$.FindAsync(id);
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public async Task<$modelname$> Create($modelname$ item)
{
var entityEntry = await dbContext.$modelname$.AddAsync(item);
return entityEntry.Entity;
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
public void Update($modelname$ item)
{
dbContext.$modelname$.Update(item);
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
public void Delete($modelname$ item)
{
dbContext.$modelname$.Remove(item);
}
}
}