Advertisement
MadCortez

Untitled

Jun 27th, 2023
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using MyCloud.Data;
  2. using MyCloud.Interfaces;
  3. using MyCloud.Models;
  4.  
  5. namespace MyCloud.Repositories
  6. {
  7.     public class UserRepository : IBaseRepository<User>
  8.     {
  9.         private readonly ApplicationDbContext _db;
  10.  
  11.         public UserRepository(ApplicationDbContext db)
  12.         {
  13.             _db = db;
  14.         }
  15.  
  16.         public IQueryable<User> GetAll()
  17.         {
  18.             return _db.Users;
  19.         }
  20.  
  21.         public async Task Delete(User entity)
  22.         {
  23.             _db.Users.Remove(entity);
  24.             await _db.SaveChangesAsync();
  25.         }
  26.  
  27.         public async Task Create(User entity)
  28.         {
  29.             await _db.Users.AddAsync(entity);
  30.             await _db.SaveChangesAsync();
  31.         }
  32.  
  33.         public async Task<User> Update(User entity)
  34.         {
  35.             _db.Users.Update(entity);
  36.             await _db.SaveChangesAsync();
  37.  
  38.             return entity;
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement