Inheritance: DbContext
Beispiel #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);
 }
Beispiel #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);
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #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;
         }
     }
 }
Beispiel #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;
 }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #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;
         }
     }
 }