Click here to Skip to main content
12,623,744 members (33,074 online)
Click here to Skip to main content

Stats

888.4K views
30.5K downloads
305 bookmarked
Posted

A Sample Silverlight 4 Application Using MEF, MVVM, and WCF RIA Services - Part 1

, 7 Jul 2011 CPOL
Part 1 of a series describing the creation of a Silverlight business application using MEF, MVVM Light, and WCF RIA Services.
IssueVision for Silverlight Setup
IssueVisionSetup.msi
setup.exe
IssueVisionSetup.msi
setup.exe
IssueVision.Silverlight
Assemblies
GalaSoft.MvvmLight.Extras.SL4.dll
GalaSoft.MvvmLight.SL4.dll
MenuControls.dll
System.Windows.Controls.DataVisualization.Toolkit.dll
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll
System.Windows.Interactivity.dll
Database
IssueVision.Client
IssueVision.Client.csproj.user
Assets
Signin.png
Controls
Properties
Views
IssueVision.Common
IssueVision.Common.csproj.user
Controls
Helpers
Models
Properties
Resources
Themes
IssueVision.Data
IssueVision.Data.csproj.user
Properties
Web
Resources
IssueVision.Data.Web
IssueVision.edmx
Helpers
MetadataClasses
Properties
Resources
Services
IssueVision.Model
IssueVision.Model.csproj.user
Properties
IssueVision.Setup
IssueVisionSetup.vdproj
IssueVision.ViewModel
IssueVision.ViewModel.csproj.user
Properties
IssueVision.Web
IssueVision.Web.csproj.user
Properties
GalaSoft.MvvmLight.Extras.SL4.dll
GalaSoft.MvvmLight.SL4.dll
MenuControls.dll
System.Windows.Controls.DataVisualization.Toolkit.dll
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll
System.Windows.Interactivity.dll
IssueVision.Client.csproj.user
Signin.png
DataSources
IssueVision.Data.Web.IssueVisionContext.datasource
IssueVision.Data.Web.PasswordResetContext.datasource
IssueVision.Common.csproj.user
IssueVision.Data.csproj.user
IssueVision.edmx
DataTypes
IssueVision.Model.csproj.user
IssueVisionSetup.vdproj
IssueVision.ViewModel.csproj.user
IssueVision.Web.csproj.user
GalaSoft.MvvmLight.Extras.SL4.dll
GalaSoft.MvvmLight.SL4.dll
MenuControls.dll
System.Windows.Controls.DataVisualization.Toolkit.dll
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll
System.Windows.Interactivity.dll
IssueVision.Client.csproj.user
Signin.png
IssueVision.Common.csproj.user
IssueVision.Data.csproj.user
IssueVision.edmx
IssueVision.Model.csproj.user
IssueVisionSetup.vdproj
IssueVision.ViewModel.csproj.user
IssueVision.Web.csproj.user
IssueVisionSetup.msi
setup.exe
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;

namespace IssueVision.Data.Web
{
    /// <summary>
    /// PasswordResetUser class client-side extensions
    /// </summary>
    public partial class PasswordResetUser
    {
         /// <summary>
        /// Stores the password the user entered in the registration UI, 
        /// even if it is invalid. This way we can validate the password
        /// confirmation adequately all the times   
        /// </summary>
        /// <remarks>
        /// This gets set on the <see cref="System.Windows.Controls.PasswordBox.PasswordChanged"/> event
        /// </remarks>
        public string ActualPassword { get; set; }

        [Display(Name = "PasswordConfirmationLabel", ResourceType = typeof(IssueVisionResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ErrorResources))]
        [CustomValidation(typeof(PasswordResetUser), "CheckPasswordConfirmation")]
        public string PasswordConfirmation
        {
            get
            {
                return this._passwordConfirmation;
            }

            set
            {
                this.ValidateProperty("PasswordConfirmation", value);
                this._passwordConfirmation = value;
                this.RaisePropertyChanged("PasswordConfirmation");
            }
        }
        private string _passwordConfirmation;

        /// <summary>
        /// Custom validation of whether new password and confirm password match
        /// </summary>
        /// <param name="passwordConfirmation"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public static ValidationResult CheckPasswordConfirmation(string passwordConfirmation, ValidationContext validationContext)
        {
            PasswordResetUser currentUser = (PasswordResetUser)validationContext.ObjectInstance;

            if (!string.IsNullOrEmpty(currentUser.ActualPassword) &&
                !string.IsNullOrEmpty(passwordConfirmation) &&
                currentUser.ActualPassword != passwordConfirmation)
            {
                return new ValidationResult(ErrorResources.ValidationErrorPasswordConfirmationMismatch, new string[] { "PasswordConfirmation" });
            }

            return ValidationResult.Success;
        }

        /// <summary>
        /// Try validate the specified property for PasswordResetUser class
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public bool TryValidateProperty(string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            if (propertyName == "Name" || propertyName == "NewPassword"
                || propertyName == "PasswordConfirmation" || propertyName == "PasswordAnswer")
            {
                ValidationContext context = new ValidationContext(this, null, null) { MemberName = propertyName };

                var validationResults = new Collection<ValidationResult>();

                if (propertyName == "Name")
                    return Validator.TryValidateProperty(this.Name, context, validationResults);
                else if (propertyName == "NewPassword")
                    return Validator.TryValidateProperty(this.NewPassword, context, validationResults);
                else if (propertyName == "PasswordConfirmation")
                    return Validator.TryValidateProperty(this.PasswordConfirmation, context, validationResults);
                else if (propertyName == "PasswordAnswer")
                    return Validator.TryValidateProperty(this.PasswordAnswer, context, validationResults);
            }
            return false;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Weidong Shen
Software Developer (Senior)
United States United States
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161128.1 | Last Updated 7 Jul 2011
Article Copyright 2010 by Weidong Shen
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid