private async Task <ContainerPageVm> GetModelData() { var response = new ContainerPageVm(); try { using (_db = new DBEntities()) { //Model initialization with grid data response.videoDetails = await _db.Containers.Select(m => new ContainerVm { VideoId = m.VideoId, IsVideo = m.IsVideo, ImageName = m.ImageName, VideoName = m.VideoName, CategoryId = m.CategoryId }).OrderBy(m => m.IsVideo).ToListAsync(); } } catch (Exception e) { Console.WriteLine(e); } return(response); }
private async Task <ContainerPageVm> GetModelData(long id) { var response = new ContainerPageVm(); try { using (db = new DBEntities()) { if (id == 0) { //Model initialization with grid data response.videoDetails = await db.Containers.Select(m => new ContainerVm { VideoId = m.VideoId, VideoName = m.VideoName, ImageName = m.ImageName, IsVideo = m.IsVideo }).OrderBy(m => m.IsVideo).ToListAsync(); } else { //Model initialization with grid data response.videoDetails = await db.Containers.Where(m => m.CategoryId == id).Select(m => new ContainerVm { VideoId = m.VideoId, VideoName = m.VideoName, ImageName = m.ImageName, IsVideo = m.IsVideo }).OrderBy(m => m.IsVideo).ToListAsync(); } var categoryDetails = await db.Categories.FindAsync(id); if (categoryDetails != null) { response.CategoryName = categoryDetails.Name; } } } catch (Exception e) { Console.WriteLine(e); } return(response); }