public IActionResult OnGetUsers(string search, int pageNr) { var list = new List <UsersViewModel>(); var users = _panelRepository.GetUsers(); decimal pagesInDecimal = (decimal)users.Count() / 20; var pages = pagesInDecimal % 1 == 0 ? pagesInDecimal : (int)pagesInDecimal + 1; if (!String.IsNullOrEmpty(search)) { search = search.ToLower(); users = users.Where(p => p.Id.ToLower().Contains(search) || p.Email.ToLower().Contains(search) || (p.FirstName + " " + p.LastName).ToLower().Contains(search)); } users = users.OrderByDescending(p => p.CreatedOnDate).Skip((pageNr - 1) * 20).Take(20); foreach (var item in users) { list.Add(new UsersViewModel() { Id = item.Id, FullName = item.FirstName + " " + item.LastName, Email = item.Email, CurrentCart = _panelRepository.HasOpenCart(item.Id), Orders = _panelRepository.HowManyOrder(item.Id), BirthDate = item.BirthDate.ToString("dd.MM.yyyy") }); } return(new JsonResult(new { totalPages = pages, users = list })); }
public void OnGet() { var users = _panelRepository.GetTopUsers().Take(10); foreach (var item in users) { Users.Add(new UsersViewModel() { Id = item.Id, Email = item.Email, FullName = item.FirstName + " " + item.LastName, Orders = _panelRepository.HowManyOrder(item.Id) }); } var products = _panelRepository.GetTopProducts().Take(10); foreach (var item in products) { Products.Add(new ProductCartViewModel() { Id = item.Id, ProductName = item.Name, Price = (decimal)_productRepository.GetCurrentPrice(item.Id).Price1, Quantity = (int)item.Quantity, Sold = _panelRepository.GetProductSales(item.Id) }); } var costOrders = _panelRepository.GetTopCostOrders().Take(10); foreach (var item in costOrders) { CostOrders.Add(new OrdersViewModel() { Id = item.Id, OrderedDate = item.LastUpdatedOnDate.Value.ToString("dd.MM.yyyy"), UsersFullName = item.User.FirstName + " " + item.User.LastName, UserId = item.User.Id, Status = item.Status.Name, TotalPrice = (decimal)item.TotalPrice }); } var productOrders = _panelRepository.GetTopProductOrders().Take(10); foreach (var item in productOrders) { ProductOrders.Add(new OrdersViewModel() { Id = item.Id, OrderedDate = item.LastUpdatedOnDate.Value.ToString("dd.MM.yyyy"), UsersFullName = item.User.FirstName + " " + item.User.LastName, UserId = item.User.Id, Status = item.Status.Name, TotalPrice = (decimal)item.TotalPrice }); } }