using
System;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Ria;
using
System.Windows.Ria.ApplicationServices;
using
SilverlightApplication8.Web;
namespace
SilverlightApplication8
{
public
partial
class
MainPage : UserControl
{
ChinookDomainContext context;
AuthenticationService authSrv;
public
MainPage()
{
InitializeComponent();
btnLoadAlbums.IsEnabled =
false
;
btnLogout.IsEnabled =
false
;
context =
new
ChinookDomainContext();
authSrv = WebContext.Current.Authentication;
authSrv.LoggedIn +=
new
EventHandler<AuthenticationEventArgs>(authSrv_LoggedIn);
authSrv.LoggedOut +=
new
EventHandler<AuthenticationEventArgs>(authSrv_LoggedOut);
}
private
void
btnLogin_Click(
object
sender, RoutedEventArgs e)
{
LoginOperation logOp = authSrv.Login(
new
LoginParameters(txtUsername.Text, txtPassword.Password));
}
private
void
btnLogout_Click(
object
sender, RoutedEventArgs e)
{
authSrv.Logout(
true
);
}
void
authSrv_LoggedIn(
object
sender, AuthenticationEventArgs e)
{
Web.User currentUser = WebContext.Current.User;
string
roles=String.Empty;
foreach
(
var
role
in
currentUser.Roles)
{
roles += String.Format(
"{0}|"
, role);
}
lblStatus.Content =String.Format(
"Kullanıcı {0} Rolleri : {1}"
,currentUser.Name,roles);
btnLoadAlbums.IsEnabled =
true
;
btnLogout.IsEnabled =
true
;
btnLogin.IsEnabled =
false
;
}
void
authSrv_LoggedOut(
object
sender, AuthenticationEventArgs e)
{
btnLogout.IsEnabled =
false
;
btnLoadAlbums.IsEnabled =
false
;
btnLogin.IsEnabled =
true
;
}
private
void
btnLoadAlbums_Click(
object
sender, RoutedEventArgs e)
{
LoadOperation<Album> op = context.Load<Album>(context.GetAlbumsQuery(1));
grdAlbums.ItemsSource = op.Entities;
}
}
}