Exemplo n.º 1
0
 public List <Customer> GetCustomers(CustomerFilterModel filterModel)
 {
     return(_context.Customers
            .Where(c => string.IsNullOrWhiteSpace(filterModel.FirstName) || c.FirstName == filterModel.FirstName)
            .Where(c => string.IsNullOrWhiteSpace(filterModel.LastName) || c.LastName == filterModel.LastName)
            .ToList());
 }
Exemplo n.º 2
0
        public ActionResult Index(CustomerFilterModel filterModel)
        {
            CustomerIndexViewModel model = new CustomerIndexViewModel()
            {
                CustomerList = filterModel.IsFiltered ? _customerService.Filter(filterModel).ToPagedList() : _customerService.GetAll().ToPagedList(1, PAGE_SIZE),
                FilterModel  = filterModel,
            };

            return(View(GetIndexViewModel(model)));
        }
Exemplo n.º 3
0
        private CustomerViewModel CustomerDataBind(CustomerFilterModel filterModel)
        {
            CustomerViewModel viewModel = new CustomerViewModel();
            CustomerParam     param     = new CustomerParam();

            viewModel.FilterModel = filterModel;
            if (!string.IsNullOrWhiteSpace(filterModel.CustomerCode))
            {
                param.CustomerCode = filterModel.CustomerCode;
            }
            viewModel.CustomerModels =
                _customerService.GetCustomerList(param.CustomerCode, filterModel.IsAll)
                .ToModelAsCollection <Customer, CustomerModel>();
            return(viewModel);
        }
Exemplo n.º 4
0
        public void TestGetCustomersFilterFirstAndLastName()
        {
            // Arrange
            var dbContext  = CustomerDbContextMocker.GetCustomerDBContext(nameof(TestGetCustomersFilterFirstAndLastName));
            var controller = new CustomerController(dbContext);
            var filter     = new CustomerFilterModel {
                FirstName = "Jo", LastName = "it"
            };

            // Act
            var response = controller.GetCustomerListAsync(filter);

            dbContext.Dispose();

            // Assert
            Assert.NotNull(response.Result);
        }
Exemplo n.º 5
0
        public ActionResult Search(CustomerFilterModel customerFilterModel)
        {
            var result = _customerService.Qery(customerFilterModel);

            return(new JsonResult
            {
                Data = new DataResponse <Customer>
                {
                    List = result,
                    TotalPages = customerFilterModel.TotalPages,
                    TotalRecords = customerFilterModel.TotalRecords,
                    StatusCode = HttpStatusCode.OK,
                    Success = true,
                    Message = "MessageSuccessed"
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                MaxJsonLength = int.MaxValue
            });
        }
        public ActionResult List(CustomerFilterModel model)
        {
            model ??= new CustomerFilterModel();

            return(View(new CustomerListModel
            {
                FilterModel = model,
                Items = model.Apply(_dbContext.CustomerOrganisations)
                        .Select(c =>
                                new CustomerListItemModel
                {
                    CustomerId = c.CustomerOrganisationId,
                    Name = c.Name,
                    PriceListType = c.PriceListType,
                    ParentName = c.ParentCustomerOrganisation.Name,
                    OrganisationNumber = c.OrganisationNumber
                }),
                AllowCreate = User.IsInRole(Roles.ApplicationAdministrator)
            }));
        }
Exemplo n.º 7
0
        public List <CustomerBasicViewModel> Filter(CustomerFilterModel model)
        {
            var items = m_Context.Customers.AsQueryable();

            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.S_FirstName))
                {
                    items = items.Where(x => x.FirstName.Contains(model.S_FirstName));
                }
                if (!string.IsNullOrEmpty(model.S_LastName))
                {
                    items = items.Where(x => x.LastName.Contains(model.S_LastName));
                }
                if (!string.IsNullOrEmpty(model.S_IdentyficationNumber))
                {
                    items = items.Where(x => x.IdentyficationNumber.Contains(model.S_IdentyficationNumber));
                }
            }
            return(_mapper.Map <List <CustomerBasicViewModel> >(items.ToList()));
        }
        public async Task <IEnumerable <DomainModels.Business.CustomerDomain.Customer> > Handle(CustomerRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Request => {nameof(CustomerRequest)}");
            //add correlation id
            request.Controller.HttpContext.Request.Headers.Add(DomainModels.Types.Identifiers.CorrelationId, new StringValues(request.CorrelationId.ToString()));

            var customerFilterModel = new CustomerFilterModel
            {
                Header = new MessageHeader
                {
                    CorrelationId = request.CorrelationId
                },
                Body   = request.Model,
                Footer = new MessageFooter
                {
                    Sender      = DomainModels.System.Identifiers.TrackingServiceName,
                    FingerPrint = request.Controller.ActionDescriptor.Id,
                    Environment = request.OperationalUnit.Environment,
                    Assembly    = request.OperationalUnit.Assembly,
                    Route       = JsonConvert.SerializeObject(new Dictionary <string, string> {
                        { DomainModels.System.Identifiers.MessagePublisherRoute, request.MiddlewareConfiguration.MessagePublisherRoute }
                    }, Defaults.JsonSerializerSettings),
                    Hint = Enum.GetName(typeof(ResponseHint), ResponseHint.OK)
                }
            };


            return(await await new Function(_logger, DomainModels.System.Identifiers.RetryCount).Decorate(async() =>
            {
                var customer = await request.MessageRequest.Request(customerFilterModel);
                if (customer != null && customer.Any())
                {
                    //in case of data related data cached, or lookup joining, you may get and link data from previous data processed and cached.
                    //in case of the other request does not require data from th other (independent calls), you should call them in separate tasks and wait to consolidate the results.
                    var vehicleFilterModel = new VehicleFilterModel
                    {
                        Header = new MessageHeader
                        {
                            CorrelationId = request.CorrelationId
                        },
                        Body = new VehicleFilter {
                            CustomerId = customer.FirstOrDefault().Id
                        },
                        Footer = new MessageFooter
                        {
                            Sender = DomainModels.System.Identifiers.TrackingServiceName,
                            FingerPrint = request.Controller.ActionDescriptor.Id,
                            Environment = request.OperationalUnit.Environment,
                            Assembly = request.OperationalUnit.Assembly,
                            Route = JsonConvert.SerializeObject(new Dictionary <string, string> {
                                { DomainModels.System.Identifiers.MessagePublisherRoute, request.MiddlewareConfiguration.MessagePublisherRoute }
                            }, Defaults.JsonSerializerSettings),
                            Hint = Enum.GetName(typeof(ResponseHint), ResponseHint.OK)
                        }
                    };
                    var customerVehicles = await request.VehicleMessageRequest.Request(vehicleFilterModel);
                    if (customerVehicles != null && customerVehicles.Any())
                    {
                        customer.FirstOrDefault().Vehicles = new HashSet <Vehicle>(customerVehicles);
                    }
                }
                return customer;
            }));
        }
Exemplo n.º 9
0
        public IEnumerable <Customer> Qery(CustomerFilterModel customerFilterModel)
        {
            try
            {
                List <Expression <Func <Customer, bool> > > filters = new List <Expression <Func <Customer, bool> > >();
                Func <IQueryable <Customer>, IOrderedQueryable <Customer> > orderBy = c => c.OrderBy(d => d.Id);

                if (!string.IsNullOrEmpty(customerFilterModel.BloodType))
                {
                    filters.Add(c => c.BloodType == customerFilterModel.BloodType);
                }
                if (!string.IsNullOrEmpty(customerFilterModel.Company))
                {
                    filters.Add(c => c.Company == customerFilterModel.Company);
                }
                if (!string.IsNullOrEmpty(customerFilterModel.EmailAddress))
                {
                    filters.Add(c => c.EmailAddress.ToLower().Contains(customerFilterModel.EmailAddress.ToLower()));
                }
                if (!string.IsNullOrEmpty(customerFilterModel.Gender))
                {
                    filters.Add(c => c.Gender == customerFilterModel.Gender);
                }
                if (!string.IsNullOrEmpty(customerFilterModel.GivenName))
                {
                    filters.Add(c => c.GivenName.ToLower().Contains(customerFilterModel.GivenName.ToLower()));
                }
                if (!string.IsNullOrEmpty(customerFilterModel.MiddleInitial))
                {
                    filters.Add(c => c.MiddleInitial.ToLower().Contains(customerFilterModel.MiddleInitial.ToLower()));
                }
                if (!string.IsNullOrEmpty(customerFilterModel.Occupation))
                {
                    filters.Add(c => c.Occupation == customerFilterModel.Occupation);
                }
                if (!string.IsNullOrEmpty(customerFilterModel.Surname))
                {
                    filters.Add(c => c.Surname.ToLower().Contains(customerFilterModel.Surname.ToLower()));
                }
                if (!string.IsNullOrEmpty(customerFilterModel.Title))
                {
                    filters.Add(c => c.Title == customerFilterModel.Title);
                }

                if (!string.IsNullOrEmpty(customerFilterModel.SortParameter))
                {
                    if (customerFilterModel.SortParameter == "BloodType")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.BloodType);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.BloodType);
                        }
                    }
                    if (customerFilterModel.SortParameter == "Company")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.Company);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.Company);
                        }
                    }
                    if (customerFilterModel.SortParameter == "EmailAddress")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.EmailAddress);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.EmailAddress);
                        }
                    }
                    if (customerFilterModel.SortParameter == "Gender")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.Gender);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.Gender);
                        }
                    }
                    if (customerFilterModel.SortParameter == "GivenName")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.GivenName);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.GivenName);
                        }
                    }
                    if (customerFilterModel.SortParameter == "MiddleInitial")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.MiddleInitial);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.MiddleInitial);
                        }
                    }
                    if (customerFilterModel.SortParameter == "Occupation")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.Occupation);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.Occupation);
                        }
                    }
                    if (customerFilterModel.SortParameter == "Surname")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.Surname);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.Surname);
                        }
                    }
                    if (customerFilterModel.SortParameter == "Title")
                    {
                        if (customerFilterModel.SortDirection)
                        {
                            orderBy = c => c.OrderBy(d => d.Title);
                        }
                        else
                        {
                            orderBy = c => c.OrderByDescending(d => d.Title);
                        }
                    }
                }
                long itemsCount;
                var  result = _unitOfWork.CustomerQueries.GetPage(out itemsCount, customerFilterModel.PageSize, customerFilterModel.SkipRecords, filters, orderBy);

                customerFilterModel.TotalRecords = itemsCount;
                customerFilterModel.TotalPages   = (customerFilterModel.TotalRecords - 1) / customerFilterModel.PageSize + 1;
                return(result.AsEnumerable());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        public ActionResult <List <Customer> > GetAll([FromQuery] CustomerFilterModel filterParams)
        {
            var customers = _customerService.GetCustomers(filterParams);

            return(Ok(customers));
        }
Exemplo n.º 11
0
        public async Task <ActionResult <IEnumerable <Customer> > > GetCustomerListAsync([FromQuery] CustomerFilterModel filter)
        {
            //Filtering logic
            Func <CustomerFilterModel, IEnumerable <Customer> > filterData = (filterModel) =>
            {
                return(_context.CustomerList.Where(p => p.FirstName.Contains(filterModel.FirstName ?? String.Empty, StringComparison.InvariantCultureIgnoreCase)
                                                   &&
                                                   p.LastName.Contains(filterModel.LastName ?? String.Empty, StringComparison.InvariantCultureIgnoreCase)
                                                   ));
            };

            //Filter Data
            var result = filterData(filter);

            return(await Task.FromResult(result.ToList()));
        }