You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetCustomersServise.cs 1.4KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Karsha_Site.Application.Interfaces.Contexts;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Karsha_Site.Common;
  6. namespace Karsha_Site.Application.Services.Costomers.Queries.GetCustomers
  7. {
  8. public class GetAboutAddressServise: IGetAboutAddressServise
  9. {
  10. private readonly IDataBaseContext _context;
  11. public GetAboutAddressServise(IDataBaseContext context) {
  12. _context = context;
  13. }
  14. public ResultAboutAddressDto Execute(RequestGetAboutAddressDto request)
  15. {
  16. var customers = _context.Customers.AsQueryable();
  17. if (!string.IsNullOrWhiteSpace(request.SearchKey))
  18. {
  19. customers = customers.Where(c => c.Address.Contains(request.SearchKey) || c.FullName.Contains(request.SearchKey));
  20. }
  21. int rowsCount = 0;
  22. var customerList = customers.ToPaged(request.Page, request.PageSize, out rowsCount).Select(p=>new GetAboutAddressDto
  23. {
  24. Code = p.Code,
  25. FullName = p.FullName,
  26. Image = p.Image,
  27. Address = p.Address,
  28. ID = p.ID,
  29. Link = p.Link
  30. }).ToList();
  31. return new ResultAboutAddressDto
  32. {
  33. CustomersDtos = customerList,
  34. Rows = rowsCount,
  35. PageSize = request.PageSize,
  36. CurrentPage = request.Page
  37. };
  38. }
  39. }
  40. }