using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using OpenRiaServices.Client;
using OpenRiaServices.Client.Authentication;
using ExampleBusinessApplication.Web;
namespace ExampleBusinessApplication.Views
public partial class Reports : Page
private AdventureWorksDomainContext context = new AdventureWorksDomainContext();
this.Title = ApplicationStrings.ReportsPageTitle;
WebContext.Current.Authentication.LoggedIn += new System.EventHandler<AuthenticationEventArgs>(Authentication_LoggedIn);
WebContext.Current.Authentication.LoggedOut += new System.EventHandler<AuthenticationEventArgs>(Authentication_LoggedOut);
private void LoadReports()
if (WebContext.Current.User.IsAuthenticated)
numberOfRows = WebContext.Current.User.DefaultRows;
WebContext.Current.User.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(User_PropertyChanged);
CustomersGrid.Visibility = System.Windows.Visibility.Collapsed;
SalesOrdersGrid.Visibility = System.Windows.Visibility.Collapsed;
LoadOperation<Product> loadProducts = context.Load(context.GetProductsQuery().Take(numberOfRows));
ProductsGrid.ItemsSource = loadProducts.Entities;
private void LoadRestrictedReports()
LoadOperation<SalesOrderHeader> loadSales = context.Load(context.GetSalesOrderHeadersQuery().Take(numberOfRows));
SalesOrdersGrid.ItemsSource = loadSales.Entities;
SalesOrdersGrid.Visibility = System.Windows.Visibility.Visible;
if (WebContext.Current.User.IsInRole("Managers"))
LoadOperation<Customer> loadCustomers = context.Load(context.GetCustomersQuery().Take(numberOfRows));
CustomersGrid.ItemsSource = loadCustomers.Entities;
CustomersGrid.Visibility = System.Windows.Visibility.Visible;
CustomersGrid.Visibility = System.Windows.Visibility.Collapsed;
void Authentication_LoggedIn(object sender, AuthenticationEventArgs e)
void Authentication_LoggedOut(object sender, AuthenticationEventArgs e)
CustomersGrid.Visibility = System.Windows.Visibility.Collapsed;
SalesOrdersGrid.Visibility = System.Windows.Visibility.Collapsed;
void User_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
if (e.PropertyName == "DefaultRows")