public async Task <PaginatedList <Post> > GetPostsByCategory(PaginationParam pageParam, int categoryId) { return(await _selahDbContext.Posts .Include(p => p.Category) .Where(post => post.CategoryId == categoryId || post.Category.ParentId == categoryId) .ToPaginatedListAsync(pageParam)); }
public IActionResult Index() { EMIHomeViewModel emiHomeVM = new EMIHomeViewModel(); var pageParam = new PaginationParam { PageIndex = 1, Limit = 6, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var events = eventRepo.GetEvents(); var eventsVM = mapper.Map <List <EventListViewModel> >(events); emiHomeVM.Events = eventsVM; var testimonies = testimonyRepo.GetTestimonies(); var testimoniesVM = mapper.Map <List <TestimonyListViewModel> >(testimonies); emiHomeVM.Testimonies = testimoniesVM; return(View(emiHomeVM)); }
public async Task <PaginatedList <Post> > GetPublishedPosts(PaginationParam pageParam) { return(await _selahDbContext.Posts .Include(p => p.Category) .Where(post => post.Published == true) .ToPaginatedListAsync(pageParam)); }
public async Task <PaginatedList <Post> > GetPublishedPostsByCategory(PaginationParam pageParam, string category) { int _categoryId = 0; switch (category) { case "sports": _categoryId = 1; break; case "relationship_and_marriage": _categoryId = 3; break; case "career": _categoryId = 4; break; case "politics": _categoryId = 2; break; case "general": _categoryId = 5; break; } return(await _selahDbContext.Posts .Include(p => p.Category) .Where(post => (post.CategoryId == _categoryId || post.ParentId == _categoryId) && post.Published == true) .ToPaginatedListAsync(pageParam)); }
public async Task <IActionResult> Post(int postId) { try { var post = await _postRepo.GetPost(postId); //var comments = await _commentRepo.GetComments(postId); PaginationParam relPgParam = new PaginationParam() { PageIndex = 1, Limit = 4, SortColoumn = "CreatedAt" }; var relatedPosts = await _postRepo.GetPublishedPostsByCategory(relPgParam, post.CategoryId); const int LIMIT = 4; var topStories = await _postRepo.GetPublishedPostsByClaps(LIMIT); var postDetailViewModel = new PostDetailViewModel() { Post = post, RelatedPosts = relatedPosts.Source, TopStories = topStories }; return(View(postDetailViewModel)); } catch { return(View()); } }
public static Pagination CreatePagination(PaginationParam paginationParam, int totalRow) { return(new Pagination() { CurrentPage = paginationParam.Page, TotalPage = (int)totalRow / paginationParam.PerPage + 1, Count = totalRow }); }
public async Task <IActionResult> GetAll([FromQuery] PaginationParam pagination, [FromQuery] QueryManufacturerDto query) { var response = await _service.GetAllManufacturerAsync(pagination, query); if (!response.Success) { return(BadRequest(response)); } return(Ok(response)); }
public async Task <IActionResult> GetAllBaskets([FromQuery] PaginationParam pagination, [FromQuery] QueryBasketDto query) { var res = await _service.GetAllBasketsAsync(pagination, query); if (res.Success) { return(Ok(res)); } return(BadRequest(res)); }
public async Task <IActionResult> GetAllWarehouseTransaction([FromQuery] PaginationParam pagination, [FromQuery] int type = 0) { var res = await _service.GetAllWarehouseTransactionsAsync(pagination, type); if (res.Success) { return(Ok(res)); } return(BadRequest(res)); }
public IActionResult Index(int pageIndex) { int page = (pageIndex == 0) ? 1 : pageIndex; var pageParam = new PaginationParam { PageIndex = page, Limit = 20, SortColoumn = "CreatedAt" }; var books = _bookRepo.GetBooks(pageParam).Result; return(View(books.Source)); }
public async Task <IActionResult> Index([FromQuery] int pageIndex = 1) { var pageParam = new PaginationParam { PageIndex = pageIndex, Limit = 20, SortColoumn = "CreatedAt" }; var notifications = await _notificationRepo.GetNotificationsByPage(pageParam); ViewBag.NotificationCount = notifications.TotalCount; ViewBag.CurrentPage = notifications.Currentpage; ViewBag.UnreadNotification = await _notificationRepo.GetUnreadNotificationCount(); return(View(notifications.Source)); }
public async Task <IActionResult> Index(int pageIndex, string category) { PostHomeViewModel postHomeVM = new PostHomeViewModel(); int page = (pageIndex == 0) ? 1 : pageIndex; var pageParam = new PaginationParam { PageIndex = page, Limit = 15, SortColoumn = "CreatedAt" }; var dontMiss = await _postRepo.GetPublishedDMPosts(); var dontMissVM = _mapper.Map <List <PostListViewModel> >(dontMiss); postHomeVM.DontMiss = dontMissVM; var topPosts = await _postRepo.GetTopPosts(); var topPostsVM = _mapper.Map <List <PostListViewModel> >(topPosts); postHomeVM.TopPosts = topPostsVM; PaginatedList <Post> latestArticles; if (category == "all" || category == null) { latestArticles = await _postRepo.GetPublishedPosts(pageParam); } else { latestArticles = await _postRepo.GetPublishedPostsByCategory(pageParam, category); } postHomeVM.TotalPostCount = latestArticles.TotalCount; postHomeVM.CurrentPage = latestArticles.Currentpage; var latestArticlesVM = _mapper.Map <List <PostListViewModel> >(latestArticles.Source); postHomeVM.LatestArticle = latestArticlesVM; ViewData["Category"] = category; ViewData["PageIndex"] = page; return(View(postHomeVM)); }
public ActionResult VolunteerIndex() { var pageParam = new PaginationParam { PageIndex = 1, Limit = 20, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var volunteers = volRepo.GetVolunteers(); return(View(volunteers)); }
public async Task <ActionResult> Index() { var pageParam = new PaginationParam { PageIndex = 1, Limit = 20, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var books = await _bookRepo.GetBooks(pageParam); return(View(books.Source)); }
public async Task <ActionResult> EventIndex() { var pageParam = new PaginationParam { PageIndex = 1, Limit = 20, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var events = _eventRepo.GetEvents(); return(View(events)); }
public async Task <IActionResult> Index() { PostHomeViewModel postHomeVM = new PostHomeViewModel(); var pageParam = new PaginationParam { PageIndex = 1, Limit = 6, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var topPosts = await _postRepo.GetTopPosts(); var topPostsVM = _mapper.Map <List <PostListViewModel> >(topPosts); postHomeVM.TopPosts = topPostsVM; var books = _bookRepo.GetHomeBooks(); postHomeVM.Books = books.ToList(); PaginatedList <Post> latestArticles; latestArticles = await _postRepo.GetPublishedPosts(pageParam); var latestArticlesVM = _mapper.Map <List <PostListViewModel> >(latestArticles.Source); postHomeVM.LatestArticle = latestArticlesVM; return(View(postHomeVM)); }
public ActionResult GalleryIndex() { var pageParam = new PaginationParam { PageIndex = 1, Limit = 20, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var pictures = _galleryRepo.GetPictures(); var picturesVM = _mapper.Map <List <GalleryListViewModel> >(pictures); return(View(picturesVM)); }
public async Task <ActionResult> Index([FromQuery] int pageIndex = 1) { Post post = new Post(); var pageParam = new PaginationParam { PageIndex = pageIndex, Limit = 20, SortColoumn = "CreatedAt" }; if (TempData.ContainsKey("Alert")) { ViewBag.Alert = TempData["Alert"].ToString(); } if (TempData.ContainsKey("Error")) { ViewBag.Error = TempData["Error"].ToString(); } var posts = await _postRepo.GetPosts(pageParam); ViewBag.PostCount = posts.TotalCount; ViewBag.CurrentPage = posts.Currentpage; return(View(posts.Source)); }
public async Task <ServiceResponse <List <GetManufacturerDto> > > GetAllManufacturerAsync(PaginationParam pagination, QueryManufacturerDto query) { var response = new ServiceResponse <List <GetManufacturerDto> >(); try { var dbManufacturers = await _context.Manufacturers .Where(x => query.Name == null?true : x.Name.Contains(query.Name)) .Skip(pagination.Skip()) .Take(pagination.PerPage) .ToListAsync(); var totalItemsQuantity = await _context.Manufacturers .Where(x => query.Name == null?true : x.Name.Contains(query.Name)) .CountAsync(); response.Data = _mapper.Map <List <GetManufacturerDto> >(dbManufacturers); response.Pagination = new Pagination { CurrentPage = pagination.Page, TotalPage = pagination.TotalPage(totalItemsQuantity), Count = totalItemsQuantity, }; return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.MANUFACTURER_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }
public async Task <PaginatedList <Post> > GetPublishedPostsByCategory(PaginationParam pageParam, int categoryId) { return(await _selahDbContext.Posts .Where(post => (post.CategoryId == categoryId || post.ParentId == categoryId) && post.Published == true) .ToPaginatedListAsync(pageParam)); }
public async Task <ServiceResponse <IEnumerable <GetWarehouseTransactionWithoutItemDto> > > GetAllWarehouseTransactionsAsync(PaginationParam pagination, int type = 0) { var response = new ServiceResponse <IEnumerable <GetWarehouseTransactionWithoutItemDto> >(); try { var warehouseTransactionType = (WarehouseTransactionType)type; var dbWarehouseTransactions = await _context.WarehouseTransactions .Include(x => x.Manufacturer) .Include(x => x.CreatedBy) .Where(x => x.TransactionType == warehouseTransactionType) .Skip((pagination.Page - 1) * pagination.PerPage) .Take(pagination.PerPage) .ToListAsync(); var totalWarehouseTransactionQuantity = await _context.WarehouseTransactions .Include(x => x.Manufacturer) .Where(x => x.TransactionType == warehouseTransactionType) .CountAsync(); response.Data = _mapper.Map <IEnumerable <GetWarehouseTransactionWithoutItemDto> >(dbWarehouseTransactions); response.Pagination = PaginationHelper.CreatePagination(pagination, totalWarehouseTransactionQuantity); return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.WAREHOUSE_TRANSACTION_ITEM_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }
public async Task <PaginatedList <Book> > GetBooks(PaginationParam pageParam) { return(await _selahDbContext.Books .Include(bk => bk.HardBook) .Include(bk => bk.SoftBook).ToPaginatedListAsync(pageParam)); }
public static async Task <PaginatedList <T> > ToPaginatedListAsync <T>(this IQueryable <T> query, PaginationParam pageParam) where T : class { return(await query.ToPaginatedListAsync(pageParam.PageIndex, pageParam.Limit, pageParam.SortColoumn)); }
public async Task <ServiceResponse <IEnumerable <GetBasketWithoutItemDto> > > GetAllBasketsAsync(PaginationParam pagination, QueryBasketDto query) { var response = new ServiceResponse <IEnumerable <GetBasketWithoutItemDto> >(); try { var dbBasketsQuery = _context.Baskets.AsQueryable(); if (query.From.HasValue) { // GTE dbBasketsQuery = dbBasketsQuery.Where(basket => basket.UpdatedAt.CompareTo(query.From.Value) > -1); } if (query.To.HasValue) { // LTE dbBasketsQuery = dbBasketsQuery.Where(basket => basket.UpdatedAt.CompareTo(query.To.Value) < 1); } if (query.Status.HasValue) { dbBasketsQuery = dbBasketsQuery.Where(basket => basket.Status == query.Status); } var dbBaskets = await dbBasketsQuery .Include(x => x.Customer) .Skip((pagination.Page - 1) * pagination.PerPage) .Take(pagination.PerPage) .ToListAsync(); var totalBasketQuantity = await dbBasketsQuery .Include(x => x.BasketItems) .CountAsync(); response.Data = _mapper.Map <IEnumerable <GetBasketWithoutItemDto> >(dbBaskets); response.Pagination = PaginationHelper.CreatePagination(pagination, totalBasketQuantity); return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.BASKET_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }
public async Task <ServiceResponse <IEnumerable <GetWarehouseItemDto> > > GetAllWarehouseItemsAsync(PaginationParam pagination, QueryWarehouseItemDto query) { var response = new ServiceResponse <IEnumerable <GetWarehouseItemDto> >(); try { var dbWarehouseItems = await _context.WarehouseItems .Include(x => x.Product).ThenInclude(p => p.Images) .Include(x => x.Product).ThenInclude(p => p.Category) .Where(x => x.Product.IsDeleted == false && (query.Name != null ? x.Product.Name.Contains(query.Name) : true)) .Skip(pagination.Skip()) .Take(pagination.PerPage) .ToListAsync(); var totalItemsQuantity = await _context.WarehouseItems .Include(x => x.Product) .Where(x => x.Product.IsDeleted == false && (query.Name != null ? x.Product.Name.Contains(query.Name) : true)) .CountAsync(); // response.Data = _mapper.Map<IEnumerable<GetWarehouseItemDto>>(dbWarehouseItems); response.Data = dbWarehouseItems.Select(item => _mapper.Map <GetWarehouseItemDto>(item)); response.Pagination = new Pagination { CurrentPage = pagination.Page, TotalPage = pagination.TotalPage(totalItemsQuantity), Count = totalItemsQuantity, }; return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.WAREHOUSE_ITEM_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }
public async Task <PaginatedList <Notification> > GetNotificationsByPage(PaginationParam pageParam) { return(await _selahDbContext.Notifications.ToPaginatedListAsync(pageParam)); }
public async Task <PaginatedList <Order> > GetOrders(PaginationParam pageParam) { return(await _selahDbContext.Orders .ToPaginatedListAsync(pageParam.PageIndex, pageParam.Limit, pageParam.SortColoumn)); }
public static async Task <PaginationResult <T> > GetPaginationResultAsync <T>(IQueryable <T> query, PaginationParam param) where T : class { if (param.SkipCount != null) { query = query.Skip((int)param.SkipCount); } if (param.MaxResultCount != null) { query = query.Take((int)param.MaxResultCount); } return(new PaginationResult <T>(await query.ToListAsync(), query.Count())); }