Пример #1
0
        /// <summary>
        /// Method to update a Section entity asynchronously.
        /// </summary>
        /// <param name="entity">A Section entity.</param>
        /// <param name="save">Save database changes ?</param>
        /// <returns>The updated <see cref="SectionEntity"/>.</returns>
        public async Task <SectionEntity> UpdateAsync(SectionEntity entity, bool save = true)
        {
            using (Db.Context)
            {
                // Try to attach entity to the database context.
                try
                {
                    Db.Context.Attach(entity);
                }
                catch (Exception e)
                {
                    log.Fatal(e.Output(), e);
                    throw e;
                }

                // Update entity.
                entity = await SectionManager.UpdateAsync(entity);

                // Check if entity is set to default.
                if (entity.IsDefault)
                {
                    await SetDefaultAsync(entity.PrimaryKey);
                }

                // Hack to delete unassociated dependencies.
                //await CleanDependenciesAsync("SectionsInACLGroups", "AclGroupId", entity.PrimaryKey, entity.AclGroupsPKeys);
                //await CleanDependenciesAsync("AlbumsInSections", "AlbumId", entity.PrimaryKey, entity.AlbumsPKeys);

                return(entity);
            }
        }