public async Task <List <UserRole> > GetUserRoles(int userId, bool isAdmin) { var userRoleCache = new UserRoleCache(Cache); List <UserRole> cacheResult = await userRoleCache.GetUserRolesFromCache(userId, isAdmin); if (cacheResult != null) { return(cacheResult); } List <UserRole> roles; using (var uow = new UnitOfWork(Context)) { var repo = new UserRoleRepository(uow); roles = await repo.GetAllWithRelated(isAdmin).Where(c => c.UserId == userId).ToListAsync(); } if (roles != null) { await userRoleCache.AddUserRolesToCache(userId, roles, isAdmin); } return(roles); }
public async Task <UserRole> GetUserRole(int userRoleId, bool isAdmin) { UserRole userRole; using (var uow = new UnitOfWork(Context)) { var repo = new UserRoleRepository(uow); userRole = await repo.GetAllWithRelated(isAdmin).Where(ur => ur.UserRoleId == userRoleId).FirstOrDefaultAsync(); } return(userRole); }