Ejemplo n.º 1
0
        public Arena.Services.Contracts.ModifyResult ImIn(Contracts.ImIn imIn)
        {
            ModifyResult result = new ModifyResult();

            result.Successful = true.ToString();
            result.Link       = "/person/1234";

            // First Name
            if (String.IsNullOrEmpty(imIn.FirstName))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "FirstNameMissing", Message = "First Name is required."
                });
                result.Link = null;
            }

            // Last Name
            if (String.IsNullOrEmpty(imIn.LastName))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "LastNameMissing", Message = "Last Name is required."
                });
                result.Link = null;
            }

            // DOB
            if (imIn.DateOfBirth == null || imIn.DateOfBirth == default(DateTime))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "DOBMissingOrInvalid", Message = "Date of Birth required and must be valid."
                });
                result.Link = null;
            }

            // Phone Number
            if (String.IsNullOrEmpty(imIn.PhoneNumber))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "PhoneNumberMissing", Message = "Phone Number is required."
                });
                result.Link = null;
            }
            else
            {
                // Match the phone number format
                if (!Regex.Match(imIn.PhoneNumber, @"^(\([2-9]\d\d\)|[2-9]\d\d) ?[-.,]? ?[2-9]\d\d ?[-.,]? ?\d{4}$").Success)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "PhoneNumberInvalid", Message = "Phone Number format is invalid: (502) 253-8000"
                    });
                    result.Link = null;
                }
            }

            // Email
            if (!String.IsNullOrEmpty(imIn.Email))
            {
                // No more required email

                /*    result.Successful = false.ToString();
                 *  result.ValidationResults.Add(new ModifyValidationResult() { Key = "EmailMissing", Message = "Email is required." });
                 *  result.Link = null;
                 * }
                 * else
                 * {*/
                // Match the email format
                if (!Regex.Match(imIn.Email, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").Success)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "EmailInvalid", Message = "Email format is invalid: [email protected]"
                    });
                    result.Link = null;
                }
            }


            // Phone Type
            Lookup phoneType = new Lookup();
            // Get all the phone number types
            LookupCollection lc = new LookupCollection();

            lc.LoadByType(38);
            String activeTypes = lc.Where(e => e.Active).Select(e => e.Value).Aggregate((current, next) => current + ", " + next);

            if (String.IsNullOrEmpty(imIn.PhoneType))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "PhoneTypeInvalid", Message = "Phone type is invalid (" + activeTypes + ")"
                });
                result.Link = null;
            }
            else
            {
                phoneType = lc.Where(e => e.Value == imIn.PhoneType).FirstOrDefault();

                if (phoneType == null)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "PhoneTypeInvalid", Message = "Phone type is invalid (" + activeTypes + ")"
                    });
                    result.Link = null;
                }
            }

            // Validate the campus
            if (String.IsNullOrEmpty(imIn.Campus))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "CampusInvalid", Message = "Campus is required."
                });
                result.Link = null;
            }



            if (result.Successful == true.ToString())
            {
                Arena.Custom.SECC.Common.Data.Person.ImIn imInTarget = new Arena.Custom.SECC.Common.Data.Person.ImIn();
                AutoMapper.Mapper.CreateMap <Contracts.ImIn, Arena.Custom.SECC.Common.Data.Person.ImIn>();
                AutoMapper.Mapper.Map <Contracts.ImIn, Arena.Custom.SECC.Common.Data.Person.ImIn>(imIn, imInTarget);
                Arena.Custom.SECC.Common.Util.ImIn imInUtil = new Arena.Custom.SECC.Common.Util.ImIn();
                if (!imInUtil.process(imInTarget))
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "ImInGeneralError", Message = "Something went wrong processing the I'm In request."
                    });
                }
            }

            return(result);
        }