public async Task <CustomerModel> Validate(CustomerModel model)
        {
            if (model.CanonicalName == string.Empty)
            {
                throw new CompanyNameIsRequiredException();
            }

            await _addressService.Validate(model.Address);

            await _phoheNumberService.Validate(model.PhoneNumber);

            await _websiteService.Validate(model.Website);

            return(model);
        }
        private async Task <SystemUserAuthenticateModel> Validate(SystemUserAuthenticateModel model)
        {
            if (await UsernameAlreadyExists(model.Username))
            {
                throw new UsernameAlreadyExistsException(model.Username);
            }

            model.NameFirst = Helpers.ToTitleCase(model.NameFirst);
            model.NameLast  = Helpers.ToTitleCase(model.NameLast);

            model.EmailAddresses = await _systemEmailAddressService.Validate(model.EmailAddresses);

            model.PhoneNumbers = await _systemPhoneNumberService.Validate(model.PhoneNumbers);

            return(model);
        }
        private async Task <CustomerModel> Validate(CustomerModel model)
        {
            if (model.Id == null)
            {
                if (await NameExists(model.CanonicalName))
                {
                    throw new CustomerAlreadyExistsException();
                }
            }
            else
            {
                if (await NotFound(new Guid(model.Id)))
                {
                    throw new CustomerNotFoundException();
                }
            }

            if (model.CanonicalName == null || model.CanonicalName == string.Empty)
            {
                throw new NameIsRequiredException();
            }
            if (model.AdminMoniker == null || model.AdminMoniker == string.Empty)
            {
                throw new MonikerIsRequiredException();
            }
            if (await MonikerExists(model.AdminMoniker))
            {
                throw new MonikerAlreadyExistsException();
            }

            model.CanonicalName = Helpers.ToTitleCase(model.CanonicalName);

            model.Address = await _systemAddressService.Validate(model.Address);

            model.PhoneNumber = await _systemPhoneNumberService.Validate(model.PhoneNumber);

            model.Website = await _systemWebsiteService.Validate(model.Website);

            model.PointOfContact = await _systemPointOfContactService.Validate(model.PointOfContact);

            return(model);
        }
        /// <summary>
        /// Creates multiple items in the System Users container.
        /// </summary>
        /// <param name="model">A SystemResetModel object.</param>
        /// <returns></returns>
        private async Task createContainerUsers(SystemResetModel model)
        {
            if (model.Users == null)
            {
                return;
            }

            foreach (SystemUserAuthenticateModel systemAuthenticationUserModel in model.Users)
            {
                //  Validate and populate lookup items.
                systemAuthenticationUserModel.EmailAddresses = await _systemEmailAddressService.Validate(systemAuthenticationUserModel.EmailAddresses);

                systemAuthenticationUserModel.PhoneNumbers = await _systemPhoneNumberService.Validate(systemAuthenticationUserModel.PhoneNumbers);

                //  Encrypt password.
                systemAuthenticationUserModel.Password = _hashingService.EncryptString(systemAuthenticationUserModel.Password);

                //  Persist item.
                await _systemUserService.CreateItem(systemAuthenticationUserModel);
            }
        }
        public async Task <PointOfContactModel> Validate(PointOfContactModel model)
        {
            if (model.FirstName == string.Empty)
            {
                throw new PointOfContactFirstNameIsRequiredException();
            }
            if (model.LastName == string.Empty)
            {
                throw new PointOfContactLastNameIsRequiredException();
            }
            if (model.Title == string.Empty)
            {
                throw new PointOfContactTitleIsRequiredException();
            }

            await _addressService.Validate(model.Address);

            await _phoheNumberService.Validate(model.PhoneNumber);

            await _emailAddressService.Validate(model.EmailAddress);

            return(model);
        }