Exemplo n.º 1
0
        public static void CreateAndAddTags(T_Article article, List<T_Tag> tags)
        {
            try
            {
                using (Entities bdd = new Entities())
                {
                    using (TransactionScope scope = new TransactionScope())
                    {

                        bdd.T_Article.Add(article);
                        bdd.SaveChanges();

                        foreach (T_Tag tag in tags)
                        {
                            T_Tag oldTag = bdd.T_Tag.Where(tg => tg.Name == tag.Name).FirstOrDefault();
                            if (oldTag == null)
                            {
                                bdd.T_Tag.Add(tag);
                                bdd.SaveChanges();
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId = tag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                            else
                            {
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId = oldTag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                        }

                        scope.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                throw;
            }
        }
Exemplo n.º 2
0
        public static void CreateAndAddTags(T_Article article, List <T_Tag> tags)
        {
            try
            {
                using (Entities bdd = new Entities())
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        bdd.T_Article.Add(article);
                        bdd.SaveChanges();

                        foreach (T_Tag tag in tags)
                        {
                            T_Tag oldTag = bdd.T_Tag.Where(tg => tg.Name == tag.Name).FirstOrDefault();
                            if (oldTag == null)
                            {
                                bdd.T_Tag.Add(tag);
                                bdd.SaveChanges();
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId     = tag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                            else
                            {
                                T_ArticleTag at = new T_ArticleTag()
                                {
                                    ArticleId = article.Id,
                                    TagId     = oldTag.Id
                                };
                                bdd.T_ArticleTag.Add(at);
                                bdd.SaveChanges();
                            }
                        }

                        scope.Complete();
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                throw;
            }
        }
Exemplo n.º 3
0
 public static void Create(T_ArticleTag articleTag)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             bdd.T_ArticleTag.Add(articleTag);
             bdd.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }
Exemplo n.º 4
0
 public static void Create(T_ArticleTag articleTag)
 {
     try
     {
         using (Entities bdd = new Entities())
         {
             bdd.T_ArticleTag.Add(articleTag);
             bdd.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         throw;
     }
 }