상속: DbContext
예제 #1
0
 public static bool Create(News news)
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             int len = 45;
             if (news.Text.Length <= len)
             {
                 news.TextMain = news.Text.Remove(len) + " ...";
             }
             else
             {
                 news.TextMain = news.Text;
             }
             db.News.Add(news);
             db.SaveChanges();
             db.Dispose();
         }
         catch (Exception)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #2
0
 public static News GetNewByID(int id)
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             News news = db.News.Find(id);
             return(news);
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
예제 #3
0
 public static bool Edit(News news)
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             db.Entry(news).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
예제 #4
0
 public static bool Edit(News news)
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             db.Entry(news).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             return true;
         }
         catch (Exception)
         {
             return false;
         }
     }
 }
예제 #5
0
 public static List<News> GetAll()
 {
     using(NewsEntities db = new NewsEntities())
     {
         try
         {
             var result = db.News.OrderByDescending(x => x.CreateDate)
                 .ThenBy(x => x.DisplayOrder)
                 .Where(x => x.IsDraft != false)
                 .ToList();
             if (result.Count > 0)
                 return result;
         }
         catch(Exception)
         {
             return null;
         }
     }
     return null;
 }
예제 #6
0
 public static List <News> GetAll()
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             var result = db.News.OrderByDescending(x => x.CreateDate)
                          .ThenBy(x => x.DisplayOrder)
                          .Where(x => x.IsDraft != false)
                          .ToList();
             if (result.Count > 0)
             {
                 return(result);
             }
         }
         catch (Exception)
         {
             return(null);
         }
     }
     return(null);
 }
예제 #7
0
 public static bool Create(News news)
 {
     using (NewsEntities db = new NewsEntities())
     {
         try
         {
             int len = 45;
             if (news.Text.Length <= len)
                 news.TextMain = news.Text.Remove(len) + " ...";
             else
                 news.TextMain = news.Text;
             db.News.Add(news);
             db.SaveChanges();
             db.Dispose();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
예제 #8
0
 public static News GetNewByID(int id)
 {
     using(NewsEntities db = new NewsEntities())
     {
         try
         {
            News news = db.News.Find(id);
            return news;
         }
         catch (Exception)
         {
             return null;
         }
     }
 }