Пример #1
0
 public static DBO.Article GetArticle(long id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article article = bdd.T_Article.Where(x => x.id == id).FirstOrDefault();
             if (article != null)
             {
                 DBO.Article result = new DBO.Article()
                 {
                     Id          = article.id,
                     Title       = article.title,
                     Content     = article.content,
                     CreatedDate = article.created_date,
                     IdCreator   = article.id_creator,
                     Validated   = article.validated
                 };
                 return(result);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
Пример #2
0
 public static bool CreateArticle(ref DBO.Article article)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article newArticle = new T_Article()
             {
                 title        = article.Title,
                 content      = article.Content,
                 id_creator   = article.IdCreator,
                 created_date = article.CreatedDate,
                 validated    = article.Validated
             };
             bdd.T_Article.Add(newArticle);
             bdd.SaveChanges();
             article.Id = newArticle.id;
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
         return(false);
     }
 }
Пример #3
0
        public static bool UpdateArticle(DBO.Article article)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_Article oldarticle = bdd.T_Article.Where(x => x.id == article.Id).FirstOrDefault();
                    if (oldarticle != null)
                    {
                        oldarticle.title        = article.Title;
                        oldarticle.content      = article.Content;
                        oldarticle.id_creator   = article.IdCreator;
                        oldarticle.validated    = article.Validated;
                        oldarticle.created_date = article.CreatedDate;

                        bdd.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }