コード例 #1
0
        public IEntity GetParent(string parentTypeName, Guid parentID, string parentUniqueKey)
        {
            IEntity parent = null;

            using (LogGroup logGroup = LogGroup.Start("Retrieving the parent for entity being created.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Parent ID: " + parentID.ToString());
                LogWriter.Debug("Parent unique key: " + parentUniqueKey);
                LogWriter.Debug("Parent type: " + parentTypeName);

                IRetrieveStrategy retrieveStrategy = RetrieveStrategy.New(parentTypeName, RequireAuthorisation);

                if (parentUniqueKey != String.Empty)
                {
                    parent = retrieveStrategy.Retrieve("UniqueKey", parentUniqueKey);
                }
                else if (parentID != Guid.Empty)
                {
                    parent = retrieveStrategy.Retrieve("ID", parentID);
                }
                else
                {
                    throw new Exception("No unique key or ID found for the parent.");
                }
            }
            return(parent);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the entities with the specified IDs.
        /// </summary>
        /// <param name="ids">The IDs of the entities to retrieve.</param>
        /// <returns>An array of the entities matching the provided IDs.</returns>
        public virtual T[] Index <T>(Guid[] ids)
            where T : IEntity
        {
            Collection <T> list = new Collection <T>();

            IRetrieveStrategy retriever = RetrieveStrategy.New <T>(RequireAuthorisation);

            foreach (Guid id in ids)
            {
                T entity = retriever.Retrieve <T>(id);

                list.Add(entity);
            }

            T[] entities = list.ToArray();

            if (RequireAuthorisation)
            {
                AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities);
            }

            React(entities);

            return(entities);
        }
コード例 #3
0
        public bool ChangePassword(string emailAddress, string oldPassword, string newPassword)
        {
            bool updated = false;

            using (LogGroup logGroup = LogGroup.StartDebug("Changing user password."))
            {
                User user = RetrieveStrategy.New <User>(RequireAuthorisation).Retrieve <User>("Email", emailAddress);

                if (user != null)
                {
                    if (user.Password == oldPassword)
                    {
                        user.Password = Crypter.EncryptPassword(newPassword);

                        UpdateStrategy.New(user, RequireAuthorisation).Update(user);

                        updated = true;
                    }
                }

                LogWriter.Debug("Updated: " + updated.ToString());
            }

            return(updated);
        }
コード例 #4
0
        /// <summary>
        /// Checks whether the specified property of the provided entity is unique.
        /// </summary>
        /// <param name="entity">The entity to validate by checking whether the provided property value is unique.</param>
        /// <param name="property">The property that is to remain unique.</param>
        /// <param name="attribute">The validate property attribute that caused the validation.</param>
        /// <returns>A value to indicate whether the provided value is unique to the provided property.</returns>
        public override bool IsValid(IEntity entity, PropertyInfo property, IValidatePropertyAttribute attribute)
        {
            bool isTaken = false;

            using (LogGroup logGroup = LogGroup.StartDebug("Validating the provided entity by ensuring the specified property value is unique."))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (property == null)
                {
                    throw new ArgumentNullException("property");
                }

                LogWriter.Debug("Property name: " + property.Name);

                LogWriter.Debug("Entity: " + entity.GetType().FullName);

                IRetrieveStrategy strategy = RetrieveStrategy.New(entity.ShortTypeName, false);

                object propertyValue = property.GetValue(entity, null);

                LogWriter.Debug("Property value: " + (propertyValue != null ? propertyValue.ToString() : String.Empty));

                IEntity existingEntity = (IEntity)strategy.Retrieve(property.Name, propertyValue);

                LogWriter.Debug("Existing entity found: " + (existingEntity != null).ToString());

                LogWriter.Debug("Provided entity ID: " + entity.ID.ToString());
                LogWriter.Debug("Existing entity ID: " + (existingEntity == null ? "[null]" : existingEntity.ID.ToString()));

                isTaken = (existingEntity != null && !existingEntity.ID.Equals(entity.ID));

                LogWriter.Debug("Is taken: " + isTaken);
            }

            return(!isTaken);
        }
コード例 #5
0
        public bool ResetViaEmail(string emailAddress, string subject, string message, string applicationUrl)
        {
            bool foundUser = false;

            using (LogGroup logGroup = LogGroup.StartDebug("Requesting password reset via email."))
            {
                User user = RetrieveStrategy.New <User>(RequireAuthorisation).Retrieve <User>("Email", emailAddress);

                if (user == null)
                {
                    foundUser = false;
                }
                else
                {
                    user.Password = CreateTemporaryPassword();

                    SendResetEmail(user, subject, message, applicationUrl);

                    foundUser = true;
                }
            }

            return(foundUser);
        }