Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 7 Jul 2011
Part 1 of a series describing the creation of a Silverlight business application using MEF, MVVM Light, and WCF RIA Services.
IssueVisionforSilverlightSetup20110630.zip
IssueVision for Silverlight Setup
IssueVisionSetup.msi
setup.exe
IssueVision_for_Silverlight_setup.zip
IssueVisionSetup.msi
setup.exe
IssueVision_Silverlight20110630.zip
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
IssueVision_Silverlight_20110316.zip
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
IssueVision_Silverlight_20110606.zip
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
IssueVision_Silverlight_Setup.zip
IssueVisionSetup.msi
setup.exe
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.ServiceModel.DomainServices.Server;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server.ApplicationServices;
using System.Runtime.Serialization;

namespace IssueVision.Data.Web
{
    /// <summary>
    /// LoginUser class derives from User class and implements IUser interface,
    /// it only exposes the following three data members to the client:
    /// Name, Password, ProfileResetFlag, and Roles
    /// </summary>
    [DataContractAttribute(IsReference = true)]
    [MetadataTypeAttribute(typeof(LoginUser.LoginUserMetadata))]
    public sealed class LoginUser : User, IUser
    {
        // This class allows you to attach custom attributes to properties
        // of the LoginUser class.
        //
        // For example, the following marks the Xyz property as a
        // required field and specifies the format for valid values:
        //    [Required]
        //    [RegularExpression("[A-Z][A-Za-z0-9]*")]
        //    [StringLength(32)]
        //    public string Xyz;
        internal sealed class LoginUserMetadata : UserMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private LoginUserMetadata()
            {
            }

            [Key]
            [Display(Name = "UserNameLabel", ResourceType = typeof(IssueVisionResources))]
            [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ErrorResources))]
            [RegularExpression("^[a-zA-Z0-9_]*$", ErrorMessageResourceName = "ValidationErrorInvalidUserName", ErrorMessageResourceType = typeof(ErrorResources))]
            public new string Name { get; set; }

            [Exclude]
            public new string Email { get; set; }

            [Exclude]
            public string FirstName { get; set; }

            [Exclude]
            public string LastName { get; set; }

            [Exclude]
            public string NewPassword { get; set; }

            [Exclude]
            public string PasswordQuestion { get; set; }

            [Exclude]
            public string PasswordAnswer { get; set; }

            [Exclude]
            public string UserType { get; set; }

            [Exclude]
            public bool IsUserMaintenance { get; set; }
        }

        [DataMember]
        public IEnumerable<string> Roles
        {
            get
            {
                if (this.UserType == "A")
                {
                    // Admin User
                    return new List<string> { 
                        IssueVisionServiceConstant.UserTypeUser, 
                        IssueVisionServiceConstant.UserTypeAdmin };
                }
                else if (this.UserType == "U")
                {
                    // Normal User
                    return new List<string> { "User" };
                }
                else
                    return new List<string>();
            }
            set
            {
                if (value.Contains(IssueVisionServiceConstant.UserTypeAdmin))
                {
                    // Admin User
                    this.UserType = "A";
                }
                else if (value.Contains(IssueVisionServiceConstant.UserTypeUser))
                {
                    // Normal User
                    this.UserType = "U";
                }
                else
                    this.UserType = String.Empty;
            }
        }
    }
}

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)

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 7 Jul 2011
Article Copyright 2010 by Weidong Shen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid