-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathFeatureService.cs
More file actions
35 lines (26 loc) · 997 Bytes
/
FeatureService.cs
File metadata and controls
35 lines (26 loc) · 997 Bytes
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
using Microsoft.EntityFrameworkCore;
namespace GettingFeaturesFromDatabase.Database.Services;
public class FeatureService : IFeatureService
{
private readonly SqliteDbContext _sqliteDbContext;
public FeatureService(SqliteDbContext sqliteDbContext)
{
_sqliteDbContext = sqliteDbContext;
}
public async Task<Feature?> GetFeatureAsync(string featureName)
{
var feature = await _sqliteDbContext.Set<Feature>().FindAsync(featureName);
return feature;
}
public async Task<IReadOnlyCollection<Feature>> GetFeatureAsync()
{
var features = await _sqliteDbContext.Set<Feature>().ToListAsync();
return features;
}
public async Task UpdateFeatureAsync(string featureName, bool isEnabled)
{
var feature = await _sqliteDbContext.Set<Feature>().FindAsync(featureName);
if (feature != null) feature.IsEnabled = isEnabled;
await _sqliteDbContext.SaveChangesAsync();
}
}