Ejemplo n.º 1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var homePage = new ArticleDAO
            {
                Id        = 1,
                Topic     = "Home Page",
                Slug      = "home-page",
                Content   = "This is the default home page. Please change me!",
                Published = Instant.FromDateTimeUtc(new DateTime(2018, 6, 19, 14, 31, 2, 265, DateTimeKind.Utc)),
                AuthorId  = Guid.Empty
            };

            var homePageHistory = ArticleHistoryDAO.FromArticle(homePage);

            homePageHistory.Id      = 1;
            homePageHistory.Article = null;

            modelBuilder.Entity <ArticleDAO>(entity =>
            {
                entity.HasIndex(a => a.Slug).IsUnique();
                entity.HasData(homePage);
            });

            modelBuilder.Entity <ArticleHistoryDAO>(entity =>
            {
                entity.HasData(homePageHistory);
            });

            modelBuilder.Entity <SlugHistoryDAO>(entity =>
            {
                entity.HasIndex(a => new { a.OldSlug, a.AddedDateTime });
            });
        }
Ejemplo n.º 2
0
        public async Task <Article> CreateArticleAndHistory(Article article)
        {
            var efArticle = ArticleDAO.FromDomain(article);

            Context.Articles.Add(efArticle);
            Context.ArticleHistories.Add(ArticleHistoryDAO.FromArticle(efArticle));
            await Context.SaveChangesAsync();

            return(efArticle.ToDomain());
        }
Ejemplo n.º 3
0
        public async Task Update(Article article)
        {
            var efArticle = ArticleDAO.FromDomain(article);

            Context.Attach(efArticle).State = EntityState.Modified;

            Context.ArticleHistories.Add(ArticleHistoryDAO.FromArticle(efArticle));

            try
            {
                await Context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await Exists(article.Id))
                {
                    throw new ArticleNotFoundException();
                }
                else
                {
                    throw;
                }
            }
        }