Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IList<User> users;
- using (AppDbContext db = new AppDbContext())
- {
- users = db.Users.Where(x => x.Active == true).ToList();
- }
- // do code to update UI
- public interface IUserService : IDisposable
- {
- IList<applicationuser> GetUsers();
- IList<AllApplicationUser> GetActiveUsers();
- AllApplicationUser GetUserView(long id);
- applicationuser GetUser(long id);
- void CreateUser(applicationuser user);
- void UpdateUser(applicationuser user);
- void DeleteUser(long id);
- void Save();
- applicationuser Authenticate(string username, string password);
- }
- class UserService : IUserService
- {
- private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
- private readonly OMEGAEntities _db;
- private bool _disposed = false;
- public UserService()
- {
- _db = new OMEGAEntities();
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- if (disposing)
- {
- _db.Dispose();
- }
- }
- _disposed = true;
- }
- public IList<applicationuser> GetUsers()
- {
- // fetch only active users that do not have the role SuperAdmin
- return _db.applicationusers.Where(u => u.roleid != 1 && u.activeflag == true).ToList();
- }
- public IList<AllApplicationUser> GetActiveUsers()
- {
- return _db.AllApplicationUsers.Where(u => u.activeflag == true && u.roleid != 1).ToList();
- }
- public AllApplicationUser GetUserView(long id)
- {
- return _db.AllApplicationUsers.Single(x => x.id == id);
- }
- public applicationuser GetUser(long id)
- {
- return _db.applicationusers.Find(id);
- }
- public void CreateUser(applicationuser user)
- {
- _db.applicationusers.Add(user);
- }
- public void UpdateUser(applicationuser user)
- {
- _db.Entry(user).State = EntityState.Modified;
- }
- public void DeleteUser(long id)
- {
- var user = _db.applicationusers.Find(id);
- _db.applicationusers.Remove(user);
- }
- public void Save()
- {
- _db.SaveChanges();
- }
- public applicationuser Authenticate(string username, string password)
- {
- applicationuser user =
- _db.applicationusers.SingleOrDefault(u => u.loginid.ToLower().Equals(username.ToLower()));
- if (user != null)
- {
- if (Common.Utils.DecryptData(user.password).Equals(password))
- {
- return user;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement