public async Task <IActionResult> GetCategoriesList(GetCategoriesListRequest request) { var query = _mongoDbService.GetCollection <Category>(Collections.Categories).AsQueryable(); if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { query = query.Where(x => x.Name.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Description.ToLower().Contains(request.SearchQuery.ToLower().Trim())); } var totalItemCount = await query.CountAsync(); var items = await query .ApplyOrdering(request.SortBy, request.SortDesc) .ApplyPaging(request.Page, request.PageSize) .ToListAsync(); var resources = new PagedListResource() { TotalItemCount = totalItemCount, ItemsList = items .Select(item => new { item.Id, item.Name, item.Description, item.Active }) .ToList() }; return(new SuccessResult(resources)); }
public async Task <IActionResult> GetUsersList(GetUsersListRequest request) { var users = _mongoDbService.GetCollection <ApplicationUser>(Collections.Users).AsQueryable(); var roles = _mongoDbService.GetCollection <ApplicationRole>(Collections.Roles).AsQueryable(); if (!string.IsNullOrWhiteSpace(request.RoleId)) { users = users.Where(x => x.Roles.Contains(request.RoleId)); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { users = users.Where(x => x.FullName.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Address.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Email.ToLower().Contains(request.SearchQuery.ToLower().Trim())); } var totalItemCount = await users.CountAsync(); var usersList = await users .ApplyOrdering(request.SortBy, request.SortDesc) .ApplyPaging(request.Page, request.PageSize) .ToListAsync(); var rolesList = await roles .ToListAsync(); var resources = new PagedListResource() { TotalItemCount = totalItemCount, ItemsList = usersList .Select(item => { var roleId = item.Roles.First(); var role = rolesList.FirstOrDefault(r => r.Id.ToString().Equals(roleId)); return(new { item.Id, item.FullName, item.Address, item.PhoneNumber, item.Email, item.Enabled, Role = new { role.Id, Name = role.Name.ToUpper() } }); }) .ToList() }; return(new SuccessResult(resources)); }
public async Task <IActionResult> GetProductsList(GetProductsListRequest request) { var products = _mongoDbService.GetCollection <Product>(Collections.Products).AsQueryable(); var categories = _mongoDbService.GetCollection <Category>(Collections.Categories).AsQueryable(); var query = from p in products join c in categories on p.CategoryId equals c.Id into joined select new { Product = p, Categories = joined }; if (!string.IsNullOrWhiteSpace(request.CategoryId)) { query = query.Where(x => x.Product.CategoryId.Equals(request.CategoryId)); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { query = query.Where(x => x.Product.Name.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Product.Description.ToLower().Contains(request.SearchQuery.ToLower().Trim())); } var totalItemCount = await query.CountAsync(); var items = await query .ApplyOrdering(request.SortBy, request.SortDesc) .ApplyPaging(request.Page, request.PageSize) .ToListAsync(); var resources = new PagedListResource() { TotalItemCount = totalItemCount, ItemsList = items .Select(item => { var category = item.Categories.FirstOrDefault(); return(new { item.Product.Id, Category = new { category.Id, category.Name, category.Active }, item.Product.Name, item.Product.Description, item.Product.Stock, item.Product.UnitPrice, item.Product.Base64Image, item.Product.Active }); }) .ToList() }; return(new SuccessResult(resources)); }
public async Task <IActionResult> GetSuppliersList(GetSuppliersListRequest request) { var query = _mongoDbService.GetCollection <Supplier>(Collections.Suppliers).AsQueryable(); if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { long.TryParse(request.SearchQuery, out long documentNumber); query = query.Where(x => x.FullName.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Address.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.Email.ToLower().Contains(request.SearchQuery.ToLower().Trim()) || x.DocumentNumber == documentNumber); } var totalItemCount = await query.CountAsync(); var items = await query .ApplyOrdering(request.SortBy, request.SortDesc) .ApplyPaging(request.Page, request.PageSize) .ToListAsync(); var resources = new PagedListResource() { TotalItemCount = totalItemCount, ItemsList = items .Select(item => { return(new { item.Id, item.FullName, item.Address, item.PhoneNumber, item.Email, item.DocumentType, item.DocumentNumber, item.Active }); }) .ToList() }; return(new SuccessResult(resources)); }
public async Task <IActionResult> GetSalesList(GetSalesListRequest request) { var sales = _mongoDbService.GetCollection <Sale>(Collections.Sales).AsQueryable(); var customers = _mongoDbService.GetCollection <Customer>(Collections.Customers).AsQueryable(); var query = from s in sales join c in customers on s.CustomerId equals c.Id into joined select new { Sale = s, Customers = joined }; if (!request.StartDate.Equals(DateTime.MinValue)) { query = query.Where(item => item.Sale.Date >= request.StartDate.Date); } if (!request.EndDate.Equals(DateTime.MinValue)) { query = query.Where(item => item.Sale.Date <= request.EndDate.Date); } if (!string.IsNullOrWhiteSpace(request.CustomerId)) { query = query.Where(x => x.Sale.CustomerId.Equals(request.CustomerId)); } var totalItemCount = await query.CountAsync(); var items = await query .ApplyOrdering(request.SortBy, request.SortDesc) .ApplyPaging(request.Page, request.PageSize) .ToListAsync(); var productsIds = items.SelectMany(i => i.Sale.Details.Select(d => d.ProductId)).Distinct().ToList(); var productFilter = Builders <Product> .Filter.In(x => x.Id, productsIds); var products = await _mongoDbService.GetCollection <Product>(Collections.Products) .Find(productFilter).ToListAsync(); var resources = new PagedListResource() { TotalItemCount = totalItemCount, ItemsList = items .Select(item => { var customer = item.Customers.FirstOrDefault(); return(new { item.Sale.Id, Customer = new { customer.Id, customer.FullName }, item.Sale.ReceiptType, item.Sale.Tax, item.Sale.Total, item.Sale.Date, item.Sale.Approved, Details = item.Sale.Details.Select(d => { var product = products.FirstOrDefault(p => p.Id.Equals(d.ProductId)); return new { d.Id, Product = new { product.Id, product.Name }, d.Quantity, d.UnitPrice, d.Discount }; }) .OrderBy(p => p.Product.Name) .ToList() }); }) .ToList() }; return(new SuccessResult(resources)); }