public List <Customer> Search(CustomerSearchDto dto)
        {
            var dataSource = DataDbContext.Set <Customer>().AsQueryable();

            if (dto.Gender.HasValue)
            {
                dataSource = dataSource.Where(c => c.Gender != null && c.Gender.Value == dto.Gender.Value);
            }

            if (dto.CustomerCategoryId > 0)
            {
                dataSource = dataSource.Where(c => c.CustomerCategory != null && c.CustomerCategory.Id == dto.CustomerCategoryId);
            }

            dataSource = dataSource.WhereDateTime(nameof(Customer.CreatorTime), dto.StartCreatorTime, dto.EndCreatorTime);

            if (!string.IsNullOrWhiteSpace(dto.Keywords))
            {
                dataSource = dataSource.Where(c => c.RealName != null && c.RealName.Contains(dto.Keywords) || c.NickName != null && c.NickName.Contains(dto.Keywords) || c.MobilePhoneNumber != null && c.MobilePhoneNumber.Contains(dto.Keywords));
            }

            dataSource = dataSource.OrderByDescending(a => a.LastModifyTime);

            if (dto.IsGetTotalCount)
            {
                dto.TotalCount = dataSource.Count();
            }

            return(dataSource.Skip(dto.StartIndex).Take(dto.PageSize).ToList());
        }
Beispiel #2
0
 public ICollection <CustomerDto> SearchCustomer(CustomerSearchDto searchCustomer)
 {
     try
     {
         var customer = _dbContext.Customer.Where(x => searchQuery(x, searchCustomer));
         if (customer != null)
         {
             ICollection <CustomerDto> customerDto = new List <CustomerDto>();
             foreach (var item in customer)
             {
                 customerDto.Add(Mappers.CustomerRepository.MapToDto(item));
             }
             return(customerDto);
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException.GetType().ToString() == "Npgsql.PostgresException")
         {
             PostgresException postgresException = (PostgresException)ex.InnerException;
             throw new NSIException("Db error: " + postgresException.Detail, Level.Error, ErrorType.DBError);
         }
         else
         {
             throw ex.InnerException;
         }
     }
     return(null);
 }
Beispiel #3
0
        public PageResult <CustomerInfoFullDto> SearchPage(CustomerSearchDto search)
        {
            var where = GetUserWhere();
            if (search.UserId.HasValue)
            {
                where += " and UserId=@UserId";
            }
            if (search.GroupId.HasValue)
            {
                where += " and GroupId=@GroupId";
            }
            if (!string.IsNullOrEmpty(search.Name))
            {
                where += " and (Name like @Name or AuthAddress like @Name)";
            }
            var order = "order by jointime desc";
            var param = new { Name = $"%{search.Name}%", search.UserId, search.GroupId };

            return(SearchPage <CustomerInfoFullDto>(search, where, order, "CustomerInfo", param: param));
            //return Connection(connection =>
            //{
            // var where = "where UserId=@UserId";
            //    if (!string.IsNullOrEmpty(search.Name))
            //        where += " and Name like @Name";
            //    var order = "order by jointime desc";
            //    var sql = $"select row_number() over({order}) as rn, * from CustomerInfo {where}";
            //    var param = new { Name = $"%{search.Name}%", search.UserId };
            //    var list = connection.Query<CustomerInfoDto>($"select * from ({sql}) as t where rn>={((search.PageIndex - 1) * search.PageSize)} and rn<={search.PageIndex * search.PageSize}", param);

            //    var total = connection.ExecuteScalar<long>($"select count(1) from CustomerInfo {where}", param);
            //    var pageCount = (long)Math.Ceiling(total * 1.0 / search.PageSize);

            //    return new PageResult<CustomerInfoDto>() { PageSize = search.PageSize, PageIndex = search.PageIndex, Items = list.ToList(),Total = total, PageCount = pageCount };
            //});
        }
Beispiel #4
0
        public ResponseResult <PageResult <CustomerInfoFullDto> > SearchPage([FromBody] CustomerSearchDto search)
        {
            var res = _customerInfoService.SearchPage(search);

            return(res.Success());
            // return res.Clone<PageResult<CustomerInfoEditDto>>().Success();
        }
Beispiel #5
0
        public ActionResult SearchByName([FromBody] CustomerSearchDto customer)
        {
            try
            {
                Response response = new Response();

                string CName = customer.Name.Replace(" ", "");


                if (string.IsNullOrEmpty(CName))
                {
                    return(this.NotFound("حداقل یک مورد را برای جستجو وارد نمایید"));
                }

                else
                {
                    var result = db.customers.Where(current => current.Name.Replace(" ", "").Contains(CName)).ToList();


                    response.Data    = result;
                    response.Status  = true;
                    response.Message = " Reseive successfully";


                    return(Ok(response));
                }
            }

            catch (Exception e)
            {
                writeException.Write(e.Message, DateTime.Now, "Customer", "Post", "Admin");
                return(this.NotFound("Dosnt Reseive successfully"));
            }
        }
Beispiel #6
0
 public bool searchQuery(Customer customerDto, CustomerSearchDto customerSearchDto)
 {
     return((customerDto.CustomerName.Contains(customerSearchDto.CustomerName) || String.IsNullOrWhiteSpace(customerSearchDto.CustomerName)) &&
            (customerDto.DateCreated >= customerSearchDto.FromCreated || customerSearchDto.FromCreated.Equals(null)) &&
            (customerDto.DateCreated <= customerSearchDto.ToCreated || customerSearchDto.ToCreated.Equals(null)) &&
            (customerDto.DateModified >= customerSearchDto.FromModified || customerSearchDto.FromModified.Equals(null)) &&
            (customerDto.DateModified <= customerSearchDto.ToModified || customerSearchDto.FromModified.Equals(null)) &&
            (customerDto.AddressId == customerSearchDto.AddressId || customerSearchDto.AddressId.Equals(null)) &&
            (customerDto.PricingPackageId == customerSearchDto.PricingPackageId || customerSearchDto.PricingPackageId.Equals(null)));
 }
 public PageResult <CustomerInfoFullDto> SearchPage_Old(CustomerSearchDto search)
 {
     //var user = _userInfoService.GetBySession();
     //if (user == null)
     //    user = new UserInfoDto() { };
     // return new PageResult<CustomerInfoDto>();
     search           = search ?? new CustomerSearchDto();
     search.PageSize  = search.PageSize < 1 ? 50 : search.PageSize;
     search.PageIndex = search.PageIndex < 1 ? 1 : search.PageIndex;
     //search.UserId = user.Id;
     return(_customerInfoDal.SearchPage(search));
 }
        public PageResult <CustomerInfoFullDto> SearchPage(CustomerSearchDto search)
        {
            search           = search ?? new CustomerSearchDto();
            search.PageSize  = search.PageSize < 1 ? 50 : search.PageSize;
            search.PageIndex = search.PageIndex < 1 ? 1 : search.PageIndex;
            var res = _customerInfoDal.SearchPage(search);

            if (res.Items.Count > 0)
            {
                var list      = _groupInfoDal.GetList(res.Items.Select(p => p.GroupId).ToArray());
                var userinfos = _userInfoDal.GetList(res.Items.Select(p => p.UserId).ToArray());
                foreach (var item in res.Items)
                {
                    item.GroupInfo = list.Find(p => p.Id == item.GroupId);
                    item.UserInfo  = userinfos.Find(p => p.Id == item.UserId);
                }
            }
            return(res);
        }
 public List <CustomerSearchDto> CUSTOMER_Search(CustomerSearchDto input)
 {
     return(procedureHelper.GetData <CustomerSearchDto>("CUSTOMER_Search", input));
 }
Beispiel #10
0
 public ICollection <CustomerDto> SearchCustomer(CustomerSearchDto customerSearch)
 {
     return(_customerRepository.SearchCustomer(customerSearch));
 }
Beispiel #11
0
 public List <CustomerSearchDto> CUSTOMER_Search([FromBody] CustomerSearchDto input)
 {
     return(CustomerAppService.CUSTOMER_Search(input));
 }
Beispiel #12
0
 public ActionResult SearchCustomers([FromBody] CustomerSearchDto customerSearch)
 {
     return(Ok(_customersManipulation.SearchCustomer(customerSearch)));
 }