Exemplo n.º 1
0
        public static List<News> GetNews(out long PageCount,
                                  long? NewsId = null, string NewsText = null,
                                  DateTime? FromDate = null, DateTime? ToDate = null,
                                  NewsStatusType? newsStatusType = NewsStatusType.Confirmed,
                                  int? newsCategoryId = null,
                                  int PageIndex = 0, int PageSize = DefaultPageSize)
        {
            int? newsStatusTypeId = null;
            if (newsStatusType.HasValue)
                newsStatusTypeId = (int)newsStatusType;

            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                var q = from m in ctx.News.Include("NewsCategories")
                        where (!NewsId.HasValue || m.NewsId == NewsId) &&
                        (!FromDate.HasValue || m.CreateDateTime >= FromDate) &&
                        (!ToDate.HasValue || m.CreateDateTime <= ToDate) &&
                        (!newsCategoryId.HasValue || m.NewsCategories.Any(o => o.NewsCategoryId == newsCategoryId)) &&
                        (!newsStatusTypeId.HasValue || m.Status == newsStatusTypeId) &&
                        (string.IsNullOrEmpty(NewsText) || m.Summary.Contains(NewsText) || m.Body.Contains(NewsText))

                        orderby m.CreateDateTime descending
                        select m;

                PageCount = q.LongCount();
                return q.Skip(PageIndex * PageSize).Take(PageSize).ToList();
            }
        }
 public static IEnumerable<DynamicPageType> GetDynamicPageType()
 {
     using (var e = new BMIKidsEntities(ConnectionString))
     {
         var q = from a in e.DynamicPageTypes
                 select a;
         return q.ToList();
     }
 }
 public static void SaveDynamicPage(DynamicPage p)
 {
     using (var ctx = new BMIKidsEntities(ConnectionString))
     {
         ctx.DynamicPages.ApplyChanges(p);
         ctx.SaveChanges();
         p.AcceptChanges();
     }
 }
 public static DynamicPage GetDynamicPageById(long? PageId)
 {
     using (var e = new BMIKidsEntities(ConnectionString))
     {
         var q = from a in e.DynamicPages
                 where (!PageId.HasValue || a.PageId == PageId.Value)
                 select a;
         return q.FirstOrDefault();
     }
 }
Exemplo n.º 5
0
        public static News GetNews(long? NewsId = null)
        {
            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                var q = from m in ctx.News.Include("NewsCategories")
                        where (!NewsId.HasValue || m.NewsId == NewsId)
                        select m;

                return q.FirstOrDefault();
            }
        }
Exemplo n.º 6
0
        public static void SaveNews(News news)
        {
            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                if (news.ChangeTracker.State == ObjectState.Unchanged)
                    news.MarkAsModified();

                ctx.News.ApplyChanges(news);
                ctx.SaveChanges();
                news.AcceptChanges();
            }
        }
Exemplo n.º 7
0
        public static List<NewsCategory> GetNewsCategory(int? NewsCategoryId = null, String NewsCategoryName = null,bool? IsVisible=true, int PageIndex = 1, int PageSize = DefaultPageSize)
        {
            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                var q = from m in ctx.NewsCategories
                        where (!NewsCategoryId.HasValue || m.NewsCategoryId == NewsCategoryId) &&
                        (!IsVisible.HasValue || m.IsVisibleCategory == IsVisible) &&
                        (string.IsNullOrEmpty(NewsCategoryName) || m.NewsCategoryName == NewsCategoryName)
                        orderby m.NewsCategoryName
                        select m;

                return q.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
            }
        }
        public static List<DynamicPage> GetDynamicPage(out int RecordCount, long? PageId = null,
                                                       int[] PageTypeIds = null, string PageName = null,
                                                       long? ParentPageId = null,
                                                       int _PageSize = DefaultPageSize, int Currentpage = 1)
        {

            using (var e = new BMIKidsEntities(ConnectionString))
            {

                if (PageTypeIds != null && PageTypeIds.Any())
                {
                    var q = from a in e.DynamicPages.WhereIn(o => o.PageTypeId, PageTypeIds)
                            where
                                (!PageId.HasValue || a.PageId == PageId.Value) &&
                                (!ParentPageId.HasValue || a.ParentPageId == ParentPageId.Value) &&
                                (string.IsNullOrEmpty(PageName) || a.PageName == PageName)
                            orderby a.PageId ascending
                            select a;
                    RecordCount = q.Count();
                    return q.Skip((Currentpage - 1) * _PageSize).Take(_PageSize).ToList();
                }
                else
                {
                    var q = from a in e.DynamicPages
                            where
                                (!PageId.HasValue || a.PageId == PageId.Value) &&
                                (!ParentPageId.HasValue || a.ParentPageId == ParentPageId.Value) &&
                                (string.IsNullOrEmpty(PageName) || a.PageName == PageName)
                            orderby a.PageId ascending
                            select a;
                    RecordCount = q.Count();
                    return q.Skip((Currentpage - 1) * _PageSize).Take(_PageSize).ToList();
                }

                
            }
        }