Пример #1
0
        /// <summary>
        /// Verify there is a UI template/album mapping for the root album in the current gallery, creating them
        /// if necessary.
        /// </summary>
        /// <param name="rootAlbum">The root album.</param>
        private static void ConfigureUiTemplateAlbumTable(AlbumDto rootAlbum)
        {
            using (var repoUiTmpl = new UiTemplateRepository())
            {
                using (var repoUiTmplA = new UiTemplateAlbumRepository(repoUiTmpl.Context))
                {
                    // Make sure each template category has at least one template assigned to the root album.
                    // We do this with a union of two queries:
                    // 1. For categories where there is at least one album assignment, determine if at least one of
                    //    those assignments is the root album.
                    // 2. Find categories without any albums at all (this is necessary because the SelectMany() in the first
                    //    query won't return any categories that don't have related records in the template/album table).
                    var dtos = repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId)
                               .SelectMany(t => t.TemplateAlbums, (t, tt) => new { t.TemplateType, tt.FKAlbumId })
                               .GroupBy(t => t.TemplateType)
                               .Where(t => t.All(ta => ta.FKAlbumId != rootAlbum.AlbumId))
                               .Select(t => t.Key)
                               .Union(repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId).GroupBy(t => t.TemplateType).Where(t => t.All(t2 => !t2.TemplateAlbums.Any())).Select(t => t.Key))
                    ;

                    foreach (var dto in dtos)
                    {
                        // We have a template type without a root album. Find the default template and assign that one.
                        var dto1 = dto;
                        repoUiTmplA.Add(new UiTemplateAlbumDto()
                        {
                            FKUiTemplateId = repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId && t.TemplateType == dto1 && t.Name.Equals("default", StringComparison.OrdinalIgnoreCase)).First().UiTemplateId,
                            FKAlbumId      = rootAlbum.AlbumId
                        });
                    }

                    repoUiTmplA.Save();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Deletes the UI templates associated with the current gallery.
 /// </summary>
 private void DeleteUiTemplates()
 {
     using (var repo = new UiTemplateRepository())
     {
         foreach (var dto in repo.Where(m => m.FKGalleryId == GalleryId))
         {
             repo.Delete(dto);
         }
         repo.Save();
     }
 }
Пример #3
0
        /// <summary>
        /// Verify there are UI templates for the current gallery that match every UI template associated with
        /// the template gallery, creating any if necessary.
        /// </summary>
        /// <returns><c>true</c> if data was changed that necessitates reloading data from the data store, <c>false</c> otherwise.</returns>
        private bool ConfigureUiTemplateTable()
        {
            var needToClearCache = false;

            using (var repoUiTmpl = new UiTemplateRepository())
            {
                var ctx = repoUiTmpl.Context;

                //repoUiTmpl.Load();
                var uiTemplatesInGallery = repoUiTmpl.Where(ui => ui.FKGalleryId == GalleryId).Select(ui => ui.TemplateType + '|' + ui.Name).ToList();

                // Get the UI templates belonging to the template gallery. We have to do a join here because the data
                // model doesn't have a relationship. (Doing so would conflict with the relationship between
                // the UITemplateAlbum and Album tables.)
                var tmplForTmplGallery = from uiTmpl in ctx.UiTemplates join g in ctx.Galleries on uiTmpl.FKGalleryId equals g.GalleryId where g.IsTemplate select uiTmpl;

                // For each UI template, make sure one exists in the gallery
                foreach (var uiTmpl in tmplForTmplGallery)
                {
                    //if (!repoUiTmpl.Local.Any(ui => ui.TemplateType == uiTmpl.TemplateType && ui.FKGalleryId == GalleryId && ui.Name == uiTmpl.Name))
                    if (!uiTemplatesInGallery.Contains(uiTmpl.TemplateType + '|' + uiTmpl.Name))
                    {
                        // We need to add a UI template
                        repoUiTmpl.Add(new UiTemplateDto()
                        {
                            TemplateType   = uiTmpl.TemplateType,
                            FKGalleryId    = GalleryId,
                            Name           = uiTmpl.Name,
                            Description    = uiTmpl.Description,
                            HtmlTemplate   = uiTmpl.HtmlTemplate,
                            ScriptTemplate = uiTmpl.ScriptTemplate
                        });

                        needToClearCache = true;
                    }
                }

                repoUiTmpl.Save();
            }

            return(needToClearCache);
        }
Пример #4
0
 /// <summary>
 /// Deletes the UI templates associated with the current gallery.
 /// </summary>
 private void DeleteUiTemplates()
 {
     using (var repo = new UiTemplateRepository())
     {
         foreach (var dto in repo.Where(m => m.FKGalleryId == GalleryId))
         {
             repo.Delete(dto);
         }
         repo.Save();
     }
 }
Пример #5
0
        /// <summary>
        /// Verify there is a UI template/album mapping for the root album in the current gallery, creating them
        /// if necessary.
        /// </summary>
        /// <param name="rootAlbum">The root album.</param>
        private static void ConfigureUiTemplateAlbumTable(AlbumDto rootAlbum)
        {
            using (var repoUiTmpl = new UiTemplateRepository())
            {
                using (var repoUiTmplA = new UiTemplateAlbumRepository(repoUiTmpl.Context))
                {
                    // Make sure each template category has at least one template assigned to the root album.
                    // We do this with a union of two queries:
                    // 1. For categories where there is at least one album assignment, determine if at least one of
                    //    those assignments is the root album.
                    // 2. Find categories without any albums at all (this is necessary because the SelectMany() in the first
                    //    query won't return any categories that don't have related records in the template/album table).
                    var dtos = repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId)
                                                             .SelectMany(t => t.TemplateAlbums, (t, tt) => new { t.TemplateType, tt.FKAlbumId })
                                                             .GroupBy(t => t.TemplateType)
                                                             .Where(t => t.All(ta => ta.FKAlbumId != rootAlbum.AlbumId))
                                                             .Select(t => t.Key)
                                                             .Union(repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId).GroupBy(t => t.TemplateType).Where(t => t.All(t2 => !t2.TemplateAlbums.Any())).Select(t => t.Key))
                                                             ;

                    foreach (var dto in dtos)
                    {
                        // We have a template type without a root album. Find the default template and assign that one.
                        var dto1 = dto;
                        repoUiTmplA.Add(new UiTemplateAlbumDto()
                        {
                            FKUiTemplateId = repoUiTmpl.Where(t => t.FKGalleryId == rootAlbum.FKGalleryId && t.TemplateType == dto1 && t.Name.Equals("default", StringComparison.OrdinalIgnoreCase)).First().UiTemplateId,
                            FKAlbumId = rootAlbum.AlbumId
                        });
                    }

                    repoUiTmplA.Save();
                }
            }
        }