コード例 #1
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            var user = e.Argument as UserPackage;

            RTM.User users = new RTM.User();
            try
            {
                var entity = new RTMEntities();
                users = DataManagement.AuthenticateUser(user.UserName, user.Password);
                if (users != null)
                {
                    UserData.CurrentUser            = users;
                    UserData.CurrentPoistion        = entity.Positions.Where(s => s.PositionId == UserData.CurrentUser.PositionId).First();
                    UserData.CurrentAccessRight     = entity.AccessRights.Where(s => s.AccessId == UserData.CurrentUser.AccessId).First();
                    UserData.OrganizationalPosition = entity.OrganizationalCharts.Where(s => s.ChartNodeId == UserData.CurrentUser.OrganizationPosition).First();
                    entity.Users.Where(s => s.UserId == UserData.CurrentUser.UserId).FirstOrDefault().LastLogin = DateTime.Now;
                    entity.SaveChanges();
                    NavigationHandler.NavigateToPageThreadSafe(this, "UserManagement/StartPage.xaml", false);
                }
                else
                {
                    ErrorHandler.ShowErrorMessage("نام کاربری یا کلمه عبور اشتباه است");
                    Password.Dispatcher.BeginInvoke((Action) delegate
                    {
                        Password.Password = "";
                    }, System.Windows.Threading.DispatcherPriority.Normal);
                }
            }
            catch (System.Exception ex)
            {
                ErrorHandler.ShowErrorMessage("ارتباط با سرور امکان پذیر نیست" + ex.Message);
            }
        }