/// <summary>
        /// Import items into the entity repository.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public override BoolErrorsItem <IList <T> > Import(IList <T> items)
        {
            // Check for overriden handler.
            if (_importHandler != null)
            {
                return(base.Import(items));
            }

            // Get the service for the enitity of type T.
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Create(items);
            bool success = true;
            IValidationResults errors = new ValidationResults();
            int ndx = 1;

            foreach (T item in items)
            {
                IEntity entity = item as IEntity;
                if (entity.Errors.HasAny)
                {
                    success = false;
                    // Now copy over the errors w/ context information( e.g. 1st entity imported ).
                    errors.Add("Item # [" + ndx + "] : ");
                    entity.Errors.EachFull(err => errors.Add(err));
                }
                ndx++;
            }
            string fullError = errors.Message();

            return(new BoolErrorsItem <IList <T> >(items, success, fullError, errors));
        }
        /// <summary>
        /// Checks that none of the strings in the array are null.
        /// </summary>
        /// <param name="items">Array of strings to check for null. e.g. "username1", "password1"</param>
        /// <param name="itemNames">Representative names of the strings supplied in the array.</param>
        /// <param name="errorSuffix">String to use at the end of each error ( if string is emtpy. )
        /// e.g. " is not supplied." would be suffixed to "Username is not supplied."</param>
        /// <param name="multiLineSeparator">Separator to use for representing multiple errors on separate lines.</param>
        /// <returns></returns>
        public static BoolMessage AreNoneNull(string[] items, string[] itemNames, string errorSuffix, string multilineSeparator)
        {
            ValidationResults errors    = new ValidationResults();
            string            separator = string.IsNullOrEmpty(multilineSeparator) ? Environment.NewLine : multilineSeparator;
            string            suffix    = string.IsNullOrEmpty(errorSuffix) ? " is not supplied." : errorSuffix;

            for (int ndx = 0; ndx < items.Length; ndx++)
            {
                if (string.IsNullOrEmpty(items[ndx]))
                {
                    errors.Add(itemNames[ndx] + suffix);
                }
            }
            bool   success      = errors.Count == 0;
            string errorMessage = success ? string.Empty : errors.Message(separator);

            return(new BoolMessage(success, errorMessage));
        }
Exemple #3
0
        /// <summary>
        /// Create the user and also return the membership status
        /// </summary>
        /// <param name="user">kishore</param>
        /// <param name="password">password</param>
        /// <param name="status">DuplicateUserName</param>
        /// <returns>Result of user creation.</returns>
        public virtual BoolMessage Create(User user, string password, ref MembershipCreateStatus status)
        {
            UserSettings       settings = (UserSettings)Settings;
            IValidationResults errors   = new ValidationResults();

            status = ValidateCreation(user, settings, errors, password, password);

            // Previous call only validated.
            if (status != MembershipCreateStatus.Success)
            {
                return(new BoolMessage(false, errors.Message()));
            }

            // Encrypt the password before saving.
            user.PasswordPlain = password;

            // Create the user.
            Create(user);
            return(new BoolMessage(!user.Errors.HasAny, user.Errors.Message()));
        }
        /// <summary>
        /// Determines whether this instance can import the specified items.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public BoolErrorsItem <IList <T> > Load(IDictionary data, string format)
        {
            var errors = new ValidationResults();
            var result = new BoolErrorsItem <IList <T> >(null, false, string.Empty, errors);

            // For each section.
            Try.CatchLog(() =>
            {
                IMapper <T> mapper = _mappers[format];
                IList <T> results  = mapper.Map(data, errors);
                result             = new BoolErrorsItem <IList <T> >(results, results != null && results.Count > 0, errors.Message(), errors);
            });
            return(result);
        }