public void Create(ArticleDTO article) { //<Tag> tags = TagModule.ReturnTags(article.Tags); string[] newTags = TagModule.ReturnTags(article.Tags); List<Tag> tags = new List<Tag>(); if (newTags != null) { foreach (var t in newTags) { var tagFromDB = Database.Tags.GetAll().FirstOrDefault(tag => tag.Name == t); if (tagFromDB != null) tags.Add(tagFromDB); else { Tag newTag = new Tag { Name = t }; tags.Add(newTag); } } } else { tags = null; } Article art = new Article { Title = article.Title, ArticleText = article.ArticleText, CreationDate = DateTime.Now, BlogId = article.BlogId, Tags = tags }; Database.Articles.Create(art); Database.Save(); }
public void Update(ArticleDTO article) { Mapper.CreateMap<ArticleDTO, Article>(); Article updateArt = Mapper.Map<ArticleDTO, Article>(article); Database.Articles.Update(updateArt); Database.Save(); }