comparison Chronosv2/source/ViewModel/LoginViewModel.cs @ 10:443821e55f06

Initial cleaned up add from Codeplex files
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 17:25:44 +0700
parents
children
comparison
equal deleted inserted replaced
9:904a9faadf8b 10:443821e55f06
1 using System;
2 using System.Windows;
3 using Chronos.Authentication;
4 using Chronos.Model;
5 using Chronos.Presentation.Core.VirtualDesktops;
6 using Chronos.Presentation.Core.Windows;
7 using Chronos.Presentation.ViewModel;
8 using nRoute.Components.Messaging;
9 using nRoute.Services;
10
11 namespace Chronos.ViewModel
12 {
13 /// <summary>
14 /// Login view view model class
15 /// </summary>
16 public sealed class LoginViewModel
17 : WindowViewModel<UserLogin>
18 {
19 #region · Data Properties ·
20
21 /// <summary>
22 /// Gets or sets the user name
23 /// </summary>
24 public string UserId
25 {
26 get { return this.Entity.UserId; }
27 set
28 {
29 if (this.Entity.UserId != value)
30 {
31 this.Entity.UserId = value;
32 this.NotifyPropertyChanged(() => UserId);
33
34 this.InquiryCommand.RequeryCanExecute();
35 }
36 }
37 }
38
39 /// <summary>
40 /// Gets or sets the password
41 /// </summary>
42 public string Password
43 {
44 get { return this.Entity.Password; }
45 set
46 {
47 if (this.Entity.Password != value)
48 {
49 this.Entity.Password = value;
50 this.NotifyPropertyChanged(() => Password);
51
52 this.InquiryCommand.RequeryCanExecute();
53 }
54 }
55 }
56
57 #endregion
58
59 #region · Constructors ·
60
61 /// <summary>
62 /// Initializes a new instance of the <see cref="LoginViewModel"/> class
63 /// </summary>
64 public LoginViewModel()
65 : base()
66 {
67 }
68
69 #endregion
70
71 #region · Overriden Methods ·
72
73 public override bool CanClose()
74 {
75 return (this.ViewMode != ViewModeType.Busy);
76 }
77
78 public override void Close()
79 {
80 this.GetService<IVirtualDesktopManager>().CloseDialog();
81 Application.Current.Shutdown();
82 }
83
84 protected override void InitializePropertyStates()
85 {
86 this.PropertyStates.Add(e => e.UserId);
87 this.PropertyStates.Add(e => e.Password);
88 }
89
90 protected override void OnViewModeChanged()
91 {
92 base.OnViewModeChanged();
93
94 if (this.PropertyStates.Count > 0)
95 {
96 this.PropertyStates[x => x.UserId].IsEditable = (this.ViewMode != ViewModeType.Busy);
97 this.PropertyStates[x => x.Password].IsEditable = (this.ViewMode != ViewModeType.Busy);
98 }
99 }
100
101 #endregion
102
103 #region · Command Actions ·
104
105 protected override bool CanInquiryData()
106 {
107 return (!String.IsNullOrEmpty(this.UserId) &&
108 !String.IsNullOrEmpty(this.Password) &&
109 this.ViewMode != ViewModeType.Busy);
110 }
111
112 protected override void OnInquiryAction(InquiryActionResult<UserLogin> result)
113 {
114 result.Data = this.Entity;
115 result.Result = InquiryActionResultType.DataFetched;
116 }
117
118 protected override void OnInquiryActionComplete(InquiryActionResult<UserLogin> result)
119 {
120 if (result.Result == InquiryActionResultType.DataFetched)
121 {
122 Channel<AuthenticationInfo>.Public.OnNext(
123 new AuthenticationInfo
124 {
125 Action = AuthenticationAction.LoggedIn,
126 UserId = this.UserId
127 }, true);
128
129 ServiceLocator.GetService<IVirtualDesktopManager>().CloseDialog();
130 }
131 else if (result.Result == InquiryActionResultType.DataNotFound)
132 {
133 this.NotificationMessage = "Username and password do not match.";
134
135 this.ViewMode = ViewModeType.Default;
136 }
137 }
138
139 #endregion
140 }
141 }