Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IUnitOfWork : IDisposable
- {
- UserRepository Users { get; }
- int Complete();
- }
- public interface IRepository <T> where T : class
- {
- T Get(int id);
- IEnumerable<T> GetAll();
- IEnumerable<T> Find(Expression<Func<T,bool>> predicate);
- void Add(T entity);
- void Remove(T entity);
- }
- public class Repository<T> : IRepository<T> where T : class
- {
- //Impelement all functions in IRepository (Actually Using EF Context functions
- }
- public class UserRepository : Repository<User>
- {
- public UserRepository(NamaContext context) : base(context)
- {
- }
- }
- public class UserService
- {
- public bool CheckLogin(User input)
- {
- using (var db = new UnitOfWork(new NamaContext()))
- {
- User dbUser = db.Users.GetByUserName(input.UserName);
- if (dbUser == null)
- return false;
- return input.Password == dbUser.Password;
- }
- }
- //other functions....
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement