예제 #1
0
        /// <summary>
        /// Saves or updates the entity without its children.
        /// </summary>
        ///
        /// <param name="entity">
        /// Entity to save or update.
        /// </param>
        ///
        /// <param name="idGenerator">
        /// ObjectIDGenerator instance to generate IDs for objects.
        /// </param>
        ///
        /// <param name="options">
        /// Optional options.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        internal int PersistWithChildren(ref VahapYigit.Test.Models.UserRole entity, ObjectIDGenerator idGenerator, SaveOptions options = null)
        {
            int rowCount = 0;

            if (entity.User != null && idGenerator.HasId(entity.User, withForceId: true) == 0)
            {
                using (var db = new UserCrud(base.UserContext))
                {
                    var child = entity.User;

                    rowCount += db.PersistWithChildren(ref child, idGenerator, options);

                    entity.IdUser = child.Id;
                }
            }

            if (entity.Role != null && idGenerator.HasId(entity.Role, withForceId: true) == 0)
            {
                using (var db = new RoleCrud(base.UserContext))
                {
                    var child = entity.Role;

                    rowCount += db.PersistWithChildren(ref child, idGenerator, options);

                    entity.IdRole = child.Id;
                }
            }

            rowCount += this.Persist(ref entity, options);

            return(rowCount);
        }
예제 #2
0
        /// <summary>
        /// Loads the Role entity associated to the current instance (entity.Role property).
        /// </summary>
        ///
        /// <param name="entity">
        /// The target entity.
        /// </param>
        public void LoadRole(ref VahapYigit.Test.Models.UserRole entity)
        {
            if (entity != null)
            {
                var options = new SearchOptions();
                options.Filters.Add(VahapYigit.Test.Models.Role.ColumnNames.Id, FilterOperator.Equals, entity.IdRole);

                using (var db = new RoleCrud(base.UserContext))
                {
                    var collection = db.Search(ref options);
                    if (collection.Count == 1)
                    {
                        entity.Role = collection[0];
                        entity.Role.UserRoleCollection.Add(entity);
                    }
                }
            }
        }