forked from MuzaffarNurillaew/Ubee
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserRepository.cs
More file actions
48 lines (40 loc) · 1.56 KB
/
UserRepository.cs
File metadata and controls
48 lines (40 loc) · 1.56 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
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Ubee.Data.Contexts;
using Ubee.Data.IRepositories;
using Ubee.Domain.Entities;
namespace Ubee.Data.Repositories;
public class UserRepository : IUserRepository
{
private readonly AppDbContext appDbContext = new AppDbContext();
public async ValueTask<User> InsertUserAsync(User user)
{
EntityEntry<User> entity = await this.appDbContext.Users.AddAsync(user);
await appDbContext.SaveChangesAsync();
return entity.Entity;
}
public async ValueTask<User> UpdateUserAsync(User user)
{
EntityEntry<User> entity = this.appDbContext.Users.Update(user);
await appDbContext.SaveChangesAsync();
return entity.Entity;
}
public async ValueTask<bool> DeleteUserAysnyc(long id)
{
User entity =
await this.appDbContext.Users.FirstOrDefaultAsync(user => user.Id.Equals(id));
if (entity is null)
return false;
this.appDbContext.Users.Remove(entity);
await this.appDbContext.SaveChangesAsync();
return true;
}
public async ValueTask<User> SelectUserAsync(Predicate<User> predicate) =>
await this.appDbContext.Users.Where(user => user.IsActive).FirstOrDefaultAsync(user => predicate(user));
public IQueryable<User> SelectAllUsers()
{
this.appDbContext.Users.Where(user => user.IsActive);
var query = "select * from \"Users\" where \"Firstname\" like '%o%'";
return this.appDbContext.Users.FromSqlRaw(query);
}
}