Click here to Skip to main content
12,455,517 members (64,162 online)
Click here to Skip to main content

Stats

870.6K views
30.5K downloads
308 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.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace IssueVision.Data.Web
{
    public sealed class IssueVisionServiceConstant
    {
        public const byte HighestPriority = 1;
        public const byte LowestPriority = 4;
        public const byte HighestSeverity = 1;
        public const byte LowestSeverity = 4;
        public const byte OpenStatusID = 0;
        public const byte ActiveStatusID = 1;
        public const byte ResolvedStatusID = 3;
        public const string UserTypeAdmin = "Admin";
        public const string UserTypeUser = "User";
    }

    public static class UserRules
    {
        /// <summary>
        /// validate user email address
        /// </summary>
        /// <param name="email"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public static ValidationResult IsValidEmail(string email, ValidationContext validationContext)
        {
            // user Email can be null
            if (email == null)
                return ValidationResult.Success;

            // Return true if strIn is in valid e-mail format.
            if (Regex.IsMatch(email,
                   @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
                   @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"))
                return ValidationResult.Success;
            return new ValidationResult(ErrorResources.ValidationErrorInvalidEmail, new[] { "Email" });
        }
    }

    public static class IssueRules
    {
        /// <summary>
        /// When status is Resolved, the ResolutionID cannot be null or zero,
        /// and when the status is not Resolved, the ResolutionID should be
        /// either null or zero.
        /// </summary>
        /// <param name="issue"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public static ValidationResult CheckStatusResolved(Issue issue, ValidationContext validationContext)
        {
            if (issue.StatusID == IssueVisionServiceConstant.ResolvedStatusID &&
                (issue.ResolutionID == null || issue.ResolutionID == 0))
                return new ValidationResult(ErrorResources.IssueResolutionIsRequired, new[] { "ResolutionID" });

            if (issue.StatusID != IssueVisionServiceConstant.ResolvedStatusID &&
                issue.ResolutionID != null && issue.ResolutionID != 0)
                return new ValidationResult(ErrorResources.IssueResolutionIsNotNeeded, new[] { "ResolutionID" });

            return ValidationResult.Success;
        }

        /// <summary>
        /// When status is Active, assigned-to-user cannot be null.
        /// </summary>
        /// <param name="issue"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public static ValidationResult CheckStatusActive(Issue issue, ValidationContext validationContext)
        {
            if (issue.StatusID == IssueVisionServiceConstant.ActiveStatusID && issue.AssignedToID == null)
                return new ValidationResult(ErrorResources.AssignedToIDIsRequired, new[] { "AssignedToID" });

            return ValidationResult.Success;
        }

        /// <summary>
        /// When status is Open, assigned-to-user should be null.
        /// </summary>
        /// <param name="issue"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public static ValidationResult CheckStatusOpen(Issue issue, ValidationContext validationContext)
        {
            if (issue.StatusID == IssueVisionServiceConstant.OpenStatusID && issue.AssignedToID != null)
                return new ValidationResult(ErrorResources.AssignedToIDIsNotNeeded, new[] { "AssignedToID" });

            return ValidationResult.Success;
        }
    }
}

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.160826.1 | Last Updated 7 Jul 2011
Article Copyright 2010 by Weidong Shen
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid