Esempio n. 1
0
        public IActionResult Create(ArticleModel model)
        {
            if (ModelState.IsValid)
            {
                using (var transaction = Context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    var article = Context.Articles.Create(
                        title: model.Title,
                        urlSlug: model.Slug,
                        authorId: model.AuthorId,
                        postprocessorAQNs: model.GetActiveProcessorNames(),
                        created: model.Created,
                        published: model.Published,
                        textAbstract: model.Abstract,
                        textContent: model.Content,
                        textConclusion: model.Conclusion
                        );
                    Context.SaveChanges();

                    Context.Tags.CreateAllIfNotExists(model.Tags);
                    Context.SaveChanges();

                    var tags = Context.Tags.SearchAll(model.Tags);
                    Context.ArticleTags.ConnectTagsToArticle(article, tags);
                    Context.SaveChanges();

                    transaction.Commit();
                }

                return(RedirectToAction(nameof(List)));
            }

            model.EditViewManagement = new ArticleModelEditViewManagement(Context.Users);
            return(View(model));
        }