Exemplo n.º 1
0
        public BaseTableViewModel <ModelAlbum> GetAlbumList(TableFilterModel data, Language lang)
        {
            var result = new BaseTableViewModel <ModelAlbum>();

            using (var db = new DataContext())
            {
                var query = db.AlbumLanguages.Include(x => x.Album)
                            .Where(x => x.LanguageId == lang.Id && x.Album.ParentId == null)
                            .OrderByDescending(x => x.Album.CreateDate).ToList();

                var countRow = query.Count();
                result.CountPage = data.PageSize != 0 ? (int)(Math.Ceiling(countRow / (decimal)data.PageSize)) : 1;
                var currentPage = result.CountPage < data.CurrentPage - 1 ? result.CountPage : data.CurrentPage - 1;
                result.CountItems = countRow;
                result.List       = query.Skip(data.PageSize * (currentPage)).Take(data.PageSize).ToList()
                                    .Select(x => new ModelAlbum()
                {
                    Id         = x.AlbumId,
                    Name       = x.Name,
                    Descrition = x.Descrition,
                    CreateDate = x.Album.CreateDate,
                    PhotoName  = x.Album.PhotoName
                }).ToList();
                return(result);
            }
        }
        public BaseTableViewModel <ModelNews> GetNewsList(TableFilterModel data, Language lang)
        {
            var result = new BaseTableViewModel <ModelNews>();

            using (var db = new DataContext())
            {
                var query = db.NewsLanguages.Include(x => x.News)
                            .Where(x => x.LanguageId == lang.Id).OrderByDescending(x => x.News.CreateDate).ToList();

                var countRow = query.Count();
                result.CountPage = data.PageSize != 0 ? (int)(Math.Ceiling(countRow / (decimal)data.PageSize)) : 1;
                var currentPage = result.CountPage < data.CurrentPage - 1 ? result.CountPage : data.CurrentPage - 1;
                result.CountItems = countRow;
                result.List       = query.Skip(data.PageSize * (currentPage)).Take(data.PageSize).ToList()
                                    .Select(x => ConverToModelNews(x)).ToList();
                return(result);
            }
        }