Esempio n. 1
0
        public void CreateEdition(EditionEdit edition)
        {
            Edition new_edition = new Edition()
            {
                Name = edition.Name,
                Price = edition.Price
            };
            Db.Editions.Create(new_edition);

            using (var db = new PeriodicalContext())
            {
                var existedEdition = db.Editions.Where(e => e.Name == new_edition.Name).FirstOrDefault();
                var category = db.Categories.Where(c => c.Name == edition.CategoryName).FirstOrDefault();
                existedEdition.Category = category;
                category.Editions.Add(existedEdition);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void CreateArticle(ArticleEdit article)
        {
            Article new_article = new Article()
            {
                Title = article.Title,
                Text = article.Text,
                ImgName = article.ImgName,
                DateTime = article.DateTime
            };
            Db.Articles.Create(new_article);

            using (var db = new PeriodicalContext())
            {
                var existedArticle = db.Articles.Where(e => e.Title == new_article.Title).FirstOrDefault();
                var edition = db.Editions.Where(e => e.Name == article.EditionName).FirstOrDefault();
                existedArticle.Edition = edition;
                edition.Articles.Add(existedArticle);
                db.SaveChanges();
            }
        }