Exemplo n.º 1
0
        public void SearchCustomer_Success()
        {
            var c1 = Add_New_Customer_With_DI(Country.GreekCountryCode);

            Assert.NotNull(c1);

            var c2 = Add_New_Customer_With_DI(Country.CyprusCountryCode);

            Assert.NotNull(c2);

            var c3 = Add_New_Customer_With_DI(Country.ItalyCountryCode);

            Assert.NotNull(c3);

            var options = new SearchCustomerOptions()
            {
                CountryCodes = { Country.GreekCountryCode, Country.CyprusCountryCode }
            };

            var customersFound = _customer
                                 .Search(options)
                                 .SingleOrDefault();

            Assert.NotNull(customersFound);
        }
Exemplo n.º 2
0
        public void CreateCustomer_Success()
        {
            ICustomerService customerService =
                new CustomerService(context_);

            var optionsCreate = new CreateCustomerOptions()
            {
                Email     = "*****@*****.**",
                FirstName = "Dimitris",
                VatNumber = 1234567889
            };

            var customer = customerService.Create(optionsCreate);

            var optionsSearch = new SearchCustomerOptions()
            {
                Email     = optionsCreate.Email,
                FirstName = optionsCreate.FirstName,
                VatNumber = optionsCreate.VatNumber
            };

            var customers = customerService.Search(optionsSearch);

            Assert.NotNull(customer);
            Assert.Equal(optionsSearch.Email, customer.Email);
            Assert.Equal(optionsSearch.VatNumber, customer.VatNumber);
            Assert.Equal(optionsSearch.FirstName, customer.FirstName);
        }
Exemplo n.º 3
0
        public IQueryable <Customer> SearchCustomers(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context_
                        .Set <Customer>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.Firstname))
            {
                query = query.Where(c => c.Firstname == options.Firstname);
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(c => c.VatNumber == options.VatNumber);
            }

            if (options.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == options.CustomerId.Value);
            }

            if (options.CreateFrom != null)
            {
                query = query.Where(c => c.Created >= options.CreateFrom);
            }

            query = query.Take(500);

            return(query);
        }
        public void SearchCountry_Success()
        {
            var customer1 = RegisterCustomer_Success(Constants.Country.GreekCountryCode);

            Assert.NotNull(customer1);

            var customer2 = RegisterCustomer_Success(Constants.Country.CyprusCountryCode);

            Assert.NotNull(customer2);

            var options = new SearchCustomerOptions()
            {
                CountryCodes = { Constants.Country.GreekCountryCode, Constants.Country.CyprusCountryCode }
            };

            var result = _customers.Search(options).ToList();

            Assert.NotNull(result);

            var res1 = result.Where(r => r.CustomerId == customer1.CustomerId)
                       .SingleOrDefault();
            var res2 = result.Where(r => r.CustomerId == customer2.CustomerId)
                       .SingleOrDefault();

            Assert.NotNull(res1);
            Assert.NotNull(res2);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Search for a customer according the options
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public IQueryable <Customer> SearchCustomer(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context_
                        .Set <Customer>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.Email))
            {
                query = query.Where(c =>
                                    c.Email == options.Email);
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(c =>
                                    c.VatNumber == options.VatNumber);
            }

            if (options.Id != null)
            {
                query = query.Where(c =>
                                    c.Id == options.Id);
            }

            return(query.Take(500));
        }
Exemplo n.º 6
0
        public IActionResult Search(SearchCustomerOptions options)
        {
            var result = customerService_
                         .SearchCustomers(options)
                         .ToList();

            return(Json(result));
        }
        public List <Customer> SearchCustomer(SearchCustomerOptions option)
        {
            var activeCustomerList = new List <Customer>(CustomerList);

            activeCustomerList = activeCustomerList
                                 .Where(c => c.Status == true).ToList();


            if (option == null)
            {
                return(null);
            }

            if (!string.IsNullOrWhiteSpace(option.Id))
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.CustomerId.Equals(option.Id))
                                     .ToList();
            }

            if (!string.IsNullOrWhiteSpace(option.Phone))
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.Phone.Equals(option.Phone))
                                     .ToList();
            }

            if (!string.IsNullOrWhiteSpace(option.Email))
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.Email.Equals(option.Email))
                                     .ToList();
            }

            if (!string.IsNullOrWhiteSpace(option.LastName))
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.LastName.Equals(option.LastName))
                                     .ToList();
            }

            if (!string.IsNullOrWhiteSpace(option.VatNumber))
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.VatNumber.Equals(option.VatNumber))
                                     .ToList();
            }

            if (option.DateCreated != null)
            {
                activeCustomerList = activeCustomerList
                                     .Where(c => c.DateCreated == option.DateCreated)
                                     .ToList();
            }


            return(activeCustomerList);
        }
Exemplo n.º 8
0
        public IQueryable <Customer> SearchCustomers(
            SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context_
                        .Set <Customer>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.FirstName))
            {
                query = query.Where(c => c.FirstName.Contains(options.FirstName));
            }

            if (!string.IsNullOrWhiteSpace(options.LastName))
            {
                query = query.Where(c => c.LastName.Contains(options.LastName));
            }

            if (!string.IsNullOrWhiteSpace(options.Email))
            {
                query = query.Where(c => c.LastName.Contains(options.Email));
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(c => c.VatNumber.Contains(options.VatNumber));
            }

            if (!string.IsNullOrWhiteSpace(options.Phone))
            {
                query = query.Where(c => c.Phone.Contains(options.Phone));
            }

            if (options.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == options.CustomerId);
            }

            if (options.CreateFrom != null)
            {
                query = query.Where(c => c.Created >= options.CreateFrom);
            }

            if (options.CreatedTo != null)
            {
                query = query.Where(c => c.Created <= options.CreatedTo);
            }

            query = query.Take(500);

            return(query);
        }
Exemplo n.º 9
0
        public List <Customer> SearchById(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }
            var result = Search(options);

            return(result.ToList());
        }
Exemplo n.º 10
0
        public IQueryable <Customer> Search(SearchCustomerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            // SELECT FROM CUSTOMER
            var q = _dbContext.Set <Customer>()
                    .AsQueryable();

            // SELECT FROM CUSTOMER WHERE CustomerId = options.CustomerId
            if (options.CustomerId != null)
            {
                q = q.Where(c => c.CustomerId == options.CustomerId);
            }

            // SELECT FROM CUSTOMER WHERE CustomerId = options.CustomerId
            // AND VatNumber = options.VatNumber
            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                q = q.Where(c => c.VatNumber == options.VatNumber);
            }

            if (!string.IsNullOrWhiteSpace(options.Firstname))
            {
                q = q.Where(c => c.Firstname == options.Firstname);
            }

            if (!string.IsNullOrWhiteSpace(options.Lastname))
            {
                q = q.Where(c => c.Lastname == options.Lastname);
            }

            if (options.CountryCodes.Any())
            {
                q = q.Where(c => options.CountryCodes.Contains(
                                c.CountryCode));
            }

            if (options.TrackResults != null &&
                !options.TrackResults.Value)
            {
                q = q.AsNoTracking();
            }

            if (options.Skip != null)
            {
                q = q.Skip(options.Skip.Value);
            }

            q = q.Take(options.MaxResults ?? 500);

            return(q);
        }
Exemplo n.º 11
0
        public List <Customer> SearchCustomers(SearchCustomerOptions options)
        {
            var filteredList = new List <Customer>(CustomerList);

            filteredList = filteredList
                           .Where(c => c.Status == true).ToList();

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                filteredList = filteredList
                               .Where(c => c.VatNumber.Equals(options.VatNumber)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(options.Email))
            {
                filteredList = filteredList
                               .Where(c => c.Email.Equals(options.Email)).ToList();
            }

            if (options.DateTime != null)
            {
                filteredList = filteredList
                               .Where(c => c.DateTime.Equals(options.DateTime)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(options.Phone))
            {
                filteredList = filteredList
                               .Where(c => c.Phone.Equals(options.Phone)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(options.Lastname))
            {
                filteredList = filteredList
                               .Where(c => c.Lastname.Equals(options.Lastname)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(options.Firstname))
            {
                filteredList = filteredList
                               .Where(c => c.Firstname.Equals(options.Firstname)).ToList();
            }

            if (options.Id != null)
            {
                filteredList = filteredList.Where(c => c.Id == options.Id).ToList();
            }

            if (options.Status != null)
            {
                filteredList = filteredList.Where(c => c.Status == options.Status).ToList();
            }

            return(filteredList);
        }
Exemplo n.º 12
0
        public IActionResult Delete([FromBody] SearchCustomerOptions options)
        {
            var customerDelete = customerService_.SearchCustomers(options);

            if (customerDelete == null)
            {
                return(BadRequest());
            }
            customerDelete.Where(c => c.CustomerId == options.CustomerId);
            return(Json(customerDelete));
        }
Exemplo n.º 13
0
        public IActionResult Search(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(BadRequest());
            }

            var query = dbContext_
                        .Set <Customer>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.Firstname))
            {
                query = query.Where(c => c.Firstname == options.Firstname);
            }

            if (!string.IsNullOrWhiteSpace(options.Lastname))
            {
                query = query.Where(c => c.Lastname == options.Lastname);
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(c => c.VatNumber == options.VatNumber);
            }

            if (!string.IsNullOrWhiteSpace(options.Email))
            {
                query = query.Where(c => c.Email == options.Email);
            }

            if (options.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == options.CustomerId.Value);
            }

            if (options.CreateFrom != null)
            {
                query = query.Where(c => c.Created >= options.CreateFrom);
            }

            if (options.CreateTo != null)
            {
                query = query.Where(c => c.Created <= options.CreateTo);
            }

            if (query == null)
            {
                return(NotFound());
            }
            return(Json(query.ToList()));
        }
        public ApiResult <IQueryable <Customer> > getCustomerby(
            [FromQuery] int id, [FromQuery] string vat,
            [FromQuery] string email, [FromQuery] string name)
        {
            SearchCustomerOptions options = new SearchCustomerOptions
            {
                Email     = email,
                FirstName = name,
                VatNumber = vat,
                Id        = id
            };

            return(custService.Search(options));
        }
Exemplo n.º 15
0
        public ApiResult <IQueryable <Customer> > Search(
            SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(ApiResult <IQueryable <Customer> > .CreateUnsuccessful
                           (StatusCode.BadRequest, "null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Email) &&
                (options.Id == null || options.Id == 0) &&
                string.IsNullOrWhiteSpace(options.VatNumber) &&
                string.IsNullOrWhiteSpace(options.FirstName)
                )
            {
                return(ApiResult <IQueryable <Customer> > .CreateUnsuccessful
                           (StatusCode.BadRequest, "null options"));
            }

            var query = context
                        .Set <Customer>()
                        .AsQueryable();

            if (options.Id != null && options.Id != 0)
            {
                query = query.Where(
                    c => c.Id == options.Id);
            }

            if (options.VatNumber != null)
            {
                query = query.Where(
                    c => c.VatNumber == options.VatNumber);
            }

            if (options.Email != null)
            {
                query = query.Where(
                    c => c.Email.Equals(options.Email));
            }

            if (!string.IsNullOrWhiteSpace(options.FirstName))
            {
                query = query
                        .Where(c => c.FirstName.Contains(options.FirstName));
            }

            return(ApiResult <IQueryable <Customer> > .CreateSuccessful(query));
        }
Exemplo n.º 16
0
        public void SearchVat_Success()
        {
            var customer = RegisterCustomer_Success(Constants.Country.GreekCountryCode);

            Assert.NotNull(customer);

            var options = new SearchCustomerOptions()
            {
                VatNumber = customer.VatNumber
            };

            var result = _customers.Search(options).SingleOrDefault();

            Assert.NotNull(result);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Return the Customer with id id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Customer GetCustomerById(int?id)
        {
            if (id == null)
            {
                return(null);
            }

            var options = new SearchCustomerOptions()
            {
                Id = id
            };

            return(SearchCustomer(options)
                   .SingleOrDefault());
        }
Exemplo n.º 18
0
        public IQueryable <Customer> SearchCustomers(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context_
                        .Set <Customer>()
                        .AsQueryable();

            if (options.CustomerId != null)
            {
                query = query.Where(x => x.CustomerId == options.CustomerId);
            }

            if (!string.IsNullOrWhiteSpace(options.FirstName))
            {
                query = query.Where(x => x.FirstName == options.FirstName);
            }

            if (!string.IsNullOrWhiteSpace(options.LastName))
            {
                query = query.Where(x => x.LastName == options.LastName);
            }

            if (!string.IsNullOrWhiteSpace(options.VatNumber))
            {
                query = query.Where(x => x.VatNumber == options.VatNumber);
            }

            if (options.CreatedFrom != null)
            {
                query = query.Where(x => x.Created >= options.CreatedFrom);
            }

            if (options.CreatedTo != null)
            {
                query = query.Where(x => x.Created <= options.CreatedTo);
            }

            if (options.IsActive != null)
            {
                query = query.Where(x => x.IsActive == options.IsActive);
            }

            return(query);
        }
Exemplo n.º 19
0
        public IActionResult Index(SearchCustomerOptions options)
        {
            options            = options ?? new SearchCustomerOptions();
            options.MaxResults = 100;

            var customers = _customers.Search(options)
                            .OrderByDescending(c => c.AuditInfo.Created)
                            .ToList();

            return(View(
                       new SearchCustomersViewModel()
            {
                Customers = customers,
                SearchOptions = options
            }));
        }
Exemplo n.º 20
0
        public IActionResult SearchCustomers([FromBody] SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(BadRequest());
            }

            var customerList = customerService_
                               .SearchCustomers(options)
                               .ToList();

            if (customerList == null)
            {
                return(NotFound());
            }

            return(Json(customerList));
        }
Exemplo n.º 21
0
        public ICollection <Model.Customer> SearchCustomer(SearchCustomerOptions options)
        {
            if (options != null)
            {
                Console.WriteLine(" selecte option");
                Console.WriteLine("1: search by vatnumber");
                Console.WriteLine("2: search by email");
                Console.WriteLine("3: search by ");
                Console.WriteLine("4: search by email");

                int choice = Convert.ToInt32(Console.ReadLine());

                if (choice == 1)
                {
                    var searchcustomer = context.Set <Customer>()
                                         .Where(s => s.VatNumber == options.VatNumber)
                                         .ToList();
                    return(searchcustomer);
                }
                else if (choice == 2)
                {
                    var searchcustomer = context.Set <Customer>()
                                         .Where(s => s.Email == options.Email)
                                         .ToList();
                    return(searchcustomer);
                }
                else if (choice == 3)
                {
                    var searchcustomer = context.Set <Customer>()
                                         .Where(s => s.Created == options.CreatedFrom)
                                         .ToList();
                    return(searchcustomer);
                }
                else if (choice == 4)
                {
                    var searchcustomer = context.Set <Customer>()
                                         .Where(s => s.Created == options.CreatedFrom)
                                         .ToList();
                    return(searchcustomer);
                }
            }
            return(null);
        }
Exemplo n.º 22
0
        public List <Customer> Search(SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context
                        .Set <Customer>()
                        .AsQueryable();

            if (options.Id != null)
            {
                query = query.Where(
                    c => c.Id == options.Id);
            }

            if (options.VatNumber != 0)
            {
                query = query.Where(
                    c => c.VatNumber == options.VatNumber);
            }

            if (options.Email != null)
            {
                query = query.Where(
                    c => c.Email == options.Email);
            }

            if (options.LastName != null)
            {
                query = query.Where(c => c.LastName.Contains(options.LastName));
            }

            if (options.FirstName != null)
            {
                query = query.Where(c => c.FirstName.Contains(options.FirstName));
            }

            return(query.ToList());
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Searches for a customer given a set of search options
        /// </summary>
        /// <param name="options">Search option</param>
        /// <returns>
        ///     A customer object of IQueryable type
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Occurs when no search options are passed
        /// </exception>
        public IQueryable <Customer> Search(SearchCustomerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var q = _dbContext.Set <Customer>()
                    .AsNoTracking()
                    .AsQueryable();

            if (options.CustomerId != null)
            {
                q = q.Where(c => c.CustomerId == options.CustomerId);
            }

            if (!string.IsNullOrWhiteSpace(options.VAtNumber))
            {
                q = q.Where(c => c.VatNumber == options.VAtNumber);
            }

            if (!string.IsNullOrWhiteSpace(options.CustBankId))
            {
                q = q.Where(c => c.CustBankID == options.CustBankId);
            }

            if (options.CountryCodes.Any())
            {
                q = q.Where(c => options.CountryCodes.Contains(c.CountryCode));
            }

            if (options.Skip != null)
            {
                q = q.Skip(options.Skip.Value);
            }

            q = q.Take(options.MaxResults ?? 500);

            return(q);
        }
 public SearchCustomersViewModel()
 {
     Customers     = new List <Customer>();
     SearchOptions = new SearchCustomerOptions();
 }
 public ApiResult <IQueryable <Customer> > getCustomerby2(
     [FromBody] SearchCustomerOptions options)
 {
     return(custService.Search(options));
 }