Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Dark-Rex01
Created December 31, 2022 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dark-Rex01/c3759c37abf2dd73ca2ca1dbd0197d2b to your computer and use it in GitHub Desktop.
Save Dark-Rex01/c3759c37abf2dd73ca2ca1dbd0197d2b to your computer and use it in GitHub Desktop.
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