Пример #1
0
 public void AddTheme(Theme newTheme)
 {
     try
     {
         _context.Add(newTheme);
     }
     catch (Exception ex)
     {
         _logger.LogError("Cannot insert Theme", ex);
     }
 }
Пример #2
0
        private void Seed_Themes()
        {
            if (!_context.Themes.Any())
            {
                var theme = new Theme()
                {
                    Name = "Media & Culture",
                    IsActive = true,
                    Topics = new List<Topic>()
                    {
                        new Topic() {Name="Music" },
                        new Topic() {Name="Film" },
                        new Topic() {Name="Reading" },
                        new Topic() {Name="Fashion" },
                        new Topic() {Name="Celebrities" },
                        new Topic() {Name="Religion" },
                        new Topic() {Name="Blogs" },
                        new Topic()
                        {
                            Name="Internet",
                            Resources = new List<Resource>()
                            {
                                new Resource() { Uri = "www.google.com"},
                                new Resource() { Uri = "www.yahoo.com"},
                                new Resource() { Uri = "www.msn.com"}
                            }

                        },
                    }

                };

                _context.Themes.Add(theme);

                if (theme.Topics != null)
                {
                    _context.Topics.AddRange(theme.Topics);
                    foreach (var topic in theme.Topics)
                    {
                        if (topic.Resources != null)
                        {
                            _context.Resources.AddRange(topic.Resources);
                        }
                     }

                }
                _context.SaveChanges();
            }
        }