public void CreateArticle(ArticleGetViewModel articleView) { var articleInJournal = new List <ArticleInJournal>(); articleInJournal.Add(new ArticleInJournal() { Journal = articleView.Journal, Article = articleView.Article }); var authorsInArticle = new List <AuthorInArticle>(); if (articleView.Authors.Count != 0) { foreach (Author author in articleView.Authors) { authorsInArticle.Add(new AuthorInArticle() { Article = articleView.Article, Author = author }); } _authorInArticleRepository.Create(authorsInArticle); } _articleInJournalRepository.Create(articleInJournal); }
public ActionResult Delete(ArticleGetViewModel journalView) { if (journalView == null) { return(HttpNotFound()); } if (journalView.Article.Id != 0) { _articleService.DeleteArticle(journalView); } return(RedirectToAction("Index")); }
public ActionResult Update(ArticleGetViewModel journalView) { if (journalView == null) { return(HttpNotFound()); } if (ModelState.IsValid) { _articleService.UpdateArticle(journalView); } return(RedirectToAction("Index")); }
public void DeleteArticle(ArticleGetViewModel articleView) { List <AuthorInArticle> authorInArticle = _authorInArticleRepository.GetArticle(articleView.Article.Id); if (authorInArticle != null) { _authorInArticleRepository.Delete(authorInArticle); } List <ArticleInJournal> articleInJournal = _articleInJournalRepository.GetJournal(articleView.Article.Id).ToList(); if (articleInJournal != null) { _articleInJournalRepository.Delete(articleInJournal); } }
public void UpdateArticle(ArticleGetViewModel articleView) { List <AuthorInArticle> authorInArticle = _authorInArticleRepository.GetArticle(articleView.Article.Id); ArticleInJournal articleInJournal = _articleInJournalRepository.GetJournal(articleView.Journal.Id).First(); if (authorInArticle != null) { List <AuthorInArticle> updateArticle = CreateAuthorInArticle(articleView, authorInArticle.First().Id); _authorInArticleRepository.Update(updateArticle); } if (articleInJournal != null) { var article = new List <ArticleInJournal>(); article.Add(articleInJournal); _articleInJournalRepository.Update(article); } }
public ArticleGetViewModel GetArticle(int id) { List <AuthorInArticle> article = _authorInArticleRepository.GetArticle(id).ToList(); var articleView = new ArticleGetViewModel(); if (article != null) { articleView = article.GroupBy(x => x.Article.Id).Select(x => new ArticleGetViewModel() { Article = x.First().Article, Authors = x.Select(z => z.Author).ToList() }).First(); } var articleInJournal = _articleInJournalRepository.GetArticle(article.First().Id); articleView.Journal = articleInJournal.First().Journal; return(articleView); }
private List <AuthorInArticle> CreateAuthorInArticle(ArticleGetViewModel articleView, int IdArticle) { var updateArticle = new List <AuthorInArticle>(); if (articleView.Authors.Count != 0) { foreach (Author author in articleView.Authors) { updateArticle.Add(new AuthorInArticle { Article = articleView.Article, Author = author, Id = IdArticle }); } } if (articleView.Authors.Count == 0) { updateArticle.Add(new AuthorInArticle { Article = articleView.Article }); } return(updateArticle); }