public async Task <IActionResult> Index(int pageIndex, string searchString) { if (pageIndex == 0) { pageIndex = 1; } int pageSize = 20; if (string.IsNullOrEmpty(searchString)) { searchString = ""; } var count = await _userRepository.CountAsync( p => (p.Nick != null && p.Nick.ToLower().Contains(searchString.ToLower())) || (p.Name != null && p.Name.ToLower().Contains(searchString.ToLower())) || (p.Surname != null && p.Surname.ToLower().Contains(searchString.ToLower())) || p.Id.ToString().Contains(searchString), null); var items = await _userRepository.GetListAsync( (pageIndex - 1) *pageSize, pageSize, p => (p.Nick != null && p.Nick.ToLower().Contains(searchString.ToLower())) || (p.Name != null && p.Name.ToLower().Contains(searchString.ToLower())) || (p.Surname != null && p.Surname.ToLower().Contains(searchString.ToLower())) || p.Id.ToString().Contains(searchString)); var tz = TZConvert.GetTimeZoneInfo("Russian Standard Time"); var list = new List <UserModel>(); items.ForEach(p => list.Add(new UserModel { Id = p.Id, Name = string.IsNullOrEmpty(p.Name) ? p.Nick : $"{p.Name} {p.Surname}", Balance = p.Balance, IsBanned = p.IsBanned, BanFineshedAt = p.BanFineshedAt != null ? TimeZoneInfo.ConvertTimeFromUtc(p.BanFineshedAt.Value.UtcDateTime, tz) : default(DateTime?), BanStartedAt = p.BanStartedAt != null ? TimeZoneInfo.ConvertTimeFromUtc(p.BanStartedAt.Value.UtcDateTime, tz) : default(DateTime?), RegistredAt = TimeZoneInfo.ConvertTimeFromUtc(p.RegistredAt.UtcDateTime, tz), })); var usersModel = new IndexViewPageModel <UserModel> { PageViewModel = new PageViewModel(count, pageIndex, pageSize), Items = list, SerachString = searchString, }; return(View(usersModel)); }
public async Task <IActionResult> ViewAuto(int pageIndex, int id) { if (pageIndex == 0 || id > 0) { pageIndex = 1; } int pageSize = 20; IList <Order> items = await _orderRepository.GetListAsync(p => (id == 0 || p.UserId == id) && p.PromoItem != null); int count = await _orderRepository.GetCount(p => (id == 0 || p.UserId == id) && p.PromoItem != null); var orders = new List <OrderModel>(); items.ToList().ForEach((obj) => { orders.Add(new OrderModel { Id = obj.Id, CategoryTitle = obj.Good.Category.Position, Cost = obj.Good.Cost, Description = obj.Good.Description, Title = obj.Good.Title, UserName = !string.IsNullOrEmpty(obj.User.Nick) ? obj.User.Nick : $"{obj.User.Name} {obj.User.Surname}", Social = obj.User?.SocialNetwork?.FirstOrDefault()?.Link, PromoCode = obj.PromoItem?.Code }); }); var ordersModel = new IndexViewPageModel <OrderModel> { PageViewModel = new PageViewModel(count, pageIndex, pageSize), Items = orders, SerachString = id.ToString() }; return(View(ordersModel)); }