Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public interface IUnitOfWork : IDisposable
  2. {
  3. UserRepository Users { get; }
  4. int Complete();
  5. }
  6.  
  7. public interface IRepository <T> where T : class
  8. {
  9. T Get(int id);
  10. IEnumerable<T> GetAll();
  11. IEnumerable<T> Find(Expression<Func<T,bool>> predicate);
  12.  
  13. void Add(T entity);
  14.  
  15. void Remove(T entity);
  16. }
  17.  
  18. public class Repository<T> : IRepository<T> where T : class
  19. {
  20.  
  21. //Impelement all functions in IRepository (Actually Using EF Context functions
  22. }
  23.  
  24. public class UserRepository : Repository<User>
  25. {
  26. public UserRepository(NamaContext context) : base(context)
  27. {
  28.  
  29. }
  30. }
  31.  
  32. public class UserService
  33. {
  34.  
  35. public bool CheckLogin(User input)
  36. {
  37. using (var db = new UnitOfWork(new NamaContext()))
  38. {
  39. User dbUser = db.Users.GetByUserName(input.UserName);
  40. if (dbUser == null)
  41. return false;
  42. return input.Password == dbUser.Password;
  43. }
  44. }
  45. //other functions....
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement