Example #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            DataAccess.Infrastructure.UserType userType = Business.AppLogic.GetUserType(this.UserTypeId);

            User oldUser = null;

            if (this.Id.HasValue)
            {
                oldUser = Business.AppLogic.GetUser(this.Id.Value);
            }

            switch (userType.UserTypeName)
            {
            case "Client Administrator":
                if (String.IsNullOrWhiteSpace(this.Password))
                {
                    yield return(new ValidationResult("Password is required.", new[] { "Password" }));
                }
                if (String.IsNullOrWhiteSpace(this.EmailAddress))
                {
                    yield return(new ValidationResult("Email Address is required.", new[] { "EmailAddress" }));
                }
                break;

            case "Vendor Administrator":
                if (String.IsNullOrWhiteSpace(this.Password))
                {
                    yield return(new ValidationResult("Password is required.", new[] { "Password" }));
                }
                if (String.IsNullOrWhiteSpace(this.EmailAddress))
                {
                    yield return(new ValidationResult("Email Address is required.", new[] { "EmailAddress" }));
                }
                if (VendorId == 0)
                {
                    yield return(new ValidationResult("Vendor is required.", new[] { "VendorId" }));
                }
                break;

            case "Office Administrator":
                if (String.IsNullOrWhiteSpace(this.Password))
                {
                    yield return(new ValidationResult("Password is required.", new[] { "Password" }));
                }
                if (String.IsNullOrWhiteSpace(this.EmailAddress))
                {
                    yield return(new ValidationResult("Email Address is required.", new[] { "EmailAddress" }));
                }
                if (VendorId == 0)
                {
                    yield return(new ValidationResult("Vendor is required.", new[] { "VendorId" }));
                }
                if (OfficeId == 0)
                {
                    yield return(new ValidationResult("Office is required.", new[] { "OfficeId" }));
                }
                break;

            case "Door to Door":
                if (String.IsNullOrWhiteSpace(this.PhoneNumber))
                {
                    yield return(new ValidationResult("Phone Number is required.", new[] { "PhoneNumber" }));
                }
                if (this.OfficeId == 0)
                {
                    yield return(new ValidationResult("Office is required.", new[] { "OfficeId" }));
                }
                if (this.VendorId == 0)
                {
                    yield return(new ValidationResult("Vendor is required.", new[] { "VendorId" }));
                }
                if (this.Gender == "?")
                {
                    yield return(new ValidationResult("Gender is required.", new[] { "Gender" }));
                }
                if (this.ShirtSize == "?")
                {
                    yield return(new ValidationResult("Shirt Size is required.", new[] { "ShirtSize" }));
                }
                if (String.IsNullOrWhiteSpace(this.City))
                {
                    yield return(new ValidationResult("City is required.", new[] { "City" }));
                }
                if (String.IsNullOrWhiteSpace(this.State))
                {
                    yield return(new ValidationResult("State is required.", new[] { "State" }));
                }

                break;

            case "Telesales":
                if (String.IsNullOrWhiteSpace(this.PhoneNumber))
                {
                    yield return(new ValidationResult("Phone Number is required.", new[] { "PhoneNumber" }));
                }
                if (this.OfficeId == 0)
                {
                    yield return(new ValidationResult("Office is required.", new[] { "OfficeId" }));
                }
                if (this.VendorId == 0)
                {
                    yield return(new ValidationResult("Vendor is required.", new[] { "VendorId" }));
                }
                //if (String.IsNullOrWhiteSpace(this.SSN))
                //    yield return new ValidationResult("Last 4 of SSN is required.", new[] { "SSN" });
                //if (String.IsNullOrWhiteSpace(this.City))
                //    yield return new ValidationResult("City is required.", new[] { "City" });
                //if (String.IsNullOrWhiteSpace(this.State))
                //    yield return new ValidationResult("State is required.", new[] { "State" });
                //if (DateTime.Compare(this.BirthDate , new DateTime(0001, 1, 1, 0, 0, 0)) == 0)
                //    yield return new ValidationResult("Birthdate is required.", new[] { "BirthDate" });

                break;

            case "Sales Administrator":
                break;



            default:
                yield return(new ValidationResult("Invalid User Type"));

                break;
            }

            if (
                (oldUser == null && VendorId.GetValueOrDefault(0) == 0 && AppLogic.GetUser(Username) != null) ||                                                        //client admin or vendor admin agent id already exists
                (oldUser == null && VendorId.GetValueOrDefault(0) > 0 && AppLogic.GetVendorUser(Username, VendorId.Value) != null) ||                                   //std user and agent id already exists for vendor
                (oldUser != null && VendorId.GetValueOrDefault(0) == 0 && oldUser.AgentId != this.Username && AppLogic.GetUser(Username) != null) ||                    //client admin or vendor admin agent id that changed already exists
                (oldUser != null && VendorId.GetValueOrDefault(0) > 0 && oldUser.AgentId != this.Username && AppLogic.GetVendorUser(Username, VendorId.Value) != null)) //std user that agent id changed and agent id already exists for vendor
            {
                yield return(new ValidationResult("Username is already assigned.", new[] { "Username" }));
            }
        }