Created
December 31, 2022 05:46
-
-
Save Dark-Rex01/c3759c37abf2dd73ca2ca1dbd0197d2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity; | |
using System.Linq; | |
namespace Repository.User | |
{ | |
public class UserRepository : IUserRepository | |
{ | |
private readonly UserDBContext _context; | |
public EmployeeRepository() | |
{ | |
_context = new UserDBContext(); | |
} | |
public UserRepository(UserDBContext context) | |
{ | |
_context = context; | |
} | |
public IEnumerable<User> GetAll() | |
{ | |
return _context.User.ToList(); | |
} | |
public User GetById(int UserID) | |
{ | |
return _context.User.Find(UserID); | |
} | |
public void Insert(User user) | |
{ | |
_context.User.Add(user); | |
} | |
public void Update(User user) | |
{ | |
_context.Entry(user).State = EntityState.Modified; | |
} | |
public void Delete(int UserID) | |
{ | |
User user = _context.user.Find(UserID); | |
_context. User.Remove(User); | |
} | |
public void Save() | |
{ | |
_context.SaveChanges(); | |
} | |
private bool disposed = false; | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!this.disposed) | |
{ | |
if (disposing) | |
{ | |
_context.Dispose(); | |
} | |
} | |
this.disposed = true; | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment