Esempio n. 1
0
        /// <summary>
        /// Loads the UserRole entities associated to the instances (entity.UserRole collection property).
        /// </summary>
        ///
        /// <param name="entities">
        /// The target entity collection.
        /// </param>
        public void LoadUserRoleCollection(TCollection <VahapYigit.Test.Models.Role> entities)
        {
            if (entities != null)
            {
                var collection = entities.Where(i => i.IsInDb).ToTCollection();
                var idList     = collection.Select(i => i.Id).ToList();

                var options = new SearchOptions();
                options.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.IdRole, FilterOperator.In, idList);

                using (var db = new UserRoleCrud(base.UserContext))
                {
                    var data = db.Search(ref options);
                    foreach (var entity in collection)
                    {
                        entity.UserRoleCollection = data.Where(i => i.IdRole == entity.Id).ToTCollection();
                    }

                    foreach (var item in data)
                    {
                        item.Role = collection.First(i => i.Id == item.IdRole);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the UserRole entities associated to the current instance (entity.UserRole collection property).
        /// </summary>
        ///
        /// <param name="entity">
        /// The target entity.
        /// </param>
        public void LoadUserRoleCollection(ref VahapYigit.Test.Models.Role entity)
        {
            if (entity != null && entity.IsInDb)
            {
                var options = new SearchOptions();
                options.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.IdRole, FilterOperator.Equals, entity.Id);

                using (var db = new UserRoleCrud(base.UserContext))
                {
                    entity.UserRoleCollection = db.Search(ref options);
                }

                foreach (var item in entity.UserRoleCollection)
                {
                    item.Role = entity;
                }
            }
        }
Esempio n. 3
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.Role entity, ObjectIDGenerator idGenerator, SaveOptions options = null)
        {
            int rowCount = 0;

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

            using (var db = new UserRoleCrud(base.UserContext))
            {
                for (int i = 0; i < entity.UserRoleCollection.Count; i++)
                {
                    var child = entity.UserRoleCollection[i];
                    child.IdRole = entity.Id;

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

            return(rowCount);
        }