Exemplo n.º 1
0
        public void DeleteByID()
        {
            var manager = new ComicStripManager(new UnitOfWork("development"));

            manager.DeleteAll();
            var publisherManager = new PublisherManager(new UnitOfWork("development"));

            publisherManager.DeleteAll();
            publisherManager.Add(new Publisher("test-publisher"));

            var AuthorManager = new AuthorManager(new UnitOfWork("development"));

            AuthorManager.DeleteAll();
            AuthorManager.Add(new Author("test-author", "test-author"));

            manager.Add(new BusinessLayer.Models.ComicStrip("test-strip", new ComicstripSerie("testSerie"), 5, AuthorManager.GetAll(), publisherManager.GetAll()[0]));
            var comic = manager.GetAll();

            Assert.AreEqual(comic.Count, 1);
            var comc = manager.Get(comic[0].ID);

            Assert.AreEqual(comc.Titel, "test-strip");
            Assert.AreEqual(comc.Number, 5);
            manager.Delete(comc.ID);
            comic = manager.GetAll();
            Assert.AreEqual(comic.Count, 0);

            publisherManager.DeleteAll();
            AuthorManager.DeleteAll();
            manager.DeleteAll();
        }
        public void Get()
        {
            var manager = new ComicStripManager(new UnitOfWork("development"));

            manager.DeleteAll();
            var publisherManager = new PublisherManager(new UnitOfWork("development"));

            publisherManager.DeleteAll();
            publisherManager.Add(new Publisher("test-publisher"));

            var AuthorManager = new AuthorManager(new UnitOfWork("development"));

            AuthorManager.DeleteAll();

            AuthorManager.Add(new Author("test-author", "test-author"));

            manager.Add(new BusinessLayer.Models.ComicStrip("test-strip", new ComicstripSerie("testSerie"), 5, AuthorManager.GetAll(), publisherManager.GetAll()[0]));
            var comic = manager.GetAll();

            var bundleManager = new ComicstripBundleManager(new UnitOfWork("development"));

            bundleManager.DeleteAll();
            bundleManager.Add(new ComicstripBundle("test-bundle", comic, publisherManager.GetAll()[0]));
            var bundles = bundleManager.GetAll();
            var bundle  = bundleManager.Get(bundles[0].ID);

            Assert.AreEqual(bundles.Count, 1);
            Assert.AreEqual(bundle.Titel, "test-bundle");
            Assert.AreEqual(bundle.Comicstrips.Count, 1);

            manager.DeleteAll();
            AuthorManager.DeleteAll();
            bundleManager.DeleteAll();
        }
 private void Submit(object sender, RoutedEventArgs e)
 {
     try
     {
         Publisher         p  = this.publishers[this.PublisherInput.SelectedIndex];
         ComicStripManager sm = new ComicStripManager(new UnitOfWork());
         ComicstripSerie   cs = null;
         if (!((bool)this.SerieSwitcher.IsChecked))
         {
             cs = this.series[this.SerieInputSelect.SelectedIndex];
         }
         else
         {
             cs = new ComicstripSerie(this.SerieInputNew.Text);
         }
         sm.Add(new ComicStrip(this.TitleInput.Text, cs, int.Parse(this.NumberInput.Text), this.AuthorsInput.GetSelected(), p));
         MessageUtil.ShowAsyncMessage("Comicstrip has been added");
         Reset();
     }
     catch (Exception ex)
     {
         MessageUtil.ShowAsyncMessage(ex.Message);
     }
 }
Exemplo n.º 4
0
        public static void import(string location)
        {
            UnitOfWork        uow = new UnitOfWork();
            ComicStripManager CM  = new ComicStripManager(uow);
            AuthorManager     AM  = new AuthorManager(uow);
            PublisherManager  PM  = new PublisherManager(uow);

            //Publisher , Author en comicStrip aan de databank toe voegen
            foreach (ComicStrip comicStrip in ReadJson(location))
            {
                try
                {
                    // Publisher toe voegen
                    if (!PM.Exist(comicStrip.Publisher, true))
                    {
                        comicStrip.SetPublisher(PM.Add(comicStrip.Publisher));
                    }
                    else
                    {
                        comicStrip.SetPublisher(PM.GetByName(comicStrip.Publisher.Name));
                    }

                    // Authors toe voegen
                    List <Author> tempAuthor = new List <Author>();
                    foreach (Author author in comicStrip.Authors)
                    {
                        if (AM.Exist(author, true))
                        {
                            tempAuthor.Add(AM.GetByName(author.Firstname, author.Surname));
                        }
                        else
                        {
                            tempAuthor.Add(AM.Add(author));
                        }
                    }
                    // Reeks toe voegen
                    if (!CM.ExistSerie(comicStrip.Serie, true))
                    {
                        comicStrip.SetSerie(CM.AddSerie(comicStrip.Serie));
                    }
                    else
                    {
                        comicStrip.SetSerie(CM.GetSerieByName(comicStrip.Serie.Name));
                    }
                    // Commiting Changes
                    comicStrip.SetAuthors(tempAuthor);
                    CM.Add(comicStrip);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            //get file dir
            List <string> split = location.Split("\\").ToList();

            split.RemoveAt(split.Count - 1);
            string newLocation = "";

            foreach (string s in split)
            {
                newLocation += s + "\\";
            }

            //get all bad comics
            List <Strip> rejectstrips = new List <Strip>();

            foreach (var key in Errors.Keys)
            {
                foreach (Strip strip in Errors[key])
                {
                    rejectstrips.Add(strip);
                }
            }

            //dump data
            string        newrawJson = JsonConvert.SerializeObject(rejectstrips);
            DirectoryInfo dir        = new DirectoryInfo(newLocation);

            File.WriteAllText(dir + "\\RejectDump.json", newrawJson);
        }