public void GivenAQueryWithTwoFilters_WhenBuildingTheList_AppropriateFiltersAreConverted() { var filter1 = new CustomerFilter { Environment_ServerName = "Env1", Gender = "M", State = "CA", StoreID = "1234" }; var filter2 = new CustomerFilter { Environment_ServerName = "Env2", Gender = "F", State = "CT", StoreID = "4231" }; var visitTrackerReportSpecification = new ReportSpecification<CustomerFilter, CustomerVisitTracker>(DateTime.Now, DateTime.UtcNow, ReportResolution.Minute, filter1, filter2); Assert.AreEqual(2, visitTrackerReportSpecification.FilterCombinations.Count()); Assert.AreEqual(4, visitTrackerReportSpecification.FilterCombinations.ElementAt(0).Filters.Count()); }
static void Test(string testName, CustomerFilter custFilter) { Console.WriteLine(testName); var custList = CustMng.FindCustomers(custFilter); CustomerManager.PrintCustomers(custList); }
public ICollection<Customer> FindCustomers(CustomerFilter custFilter) { var resultList = new List<Customer>(); foreach (var cust in _custList) { if (custFilter(cust)) resultList.Add(cust); } return resultList; }
public void IntegrationTest_GivenFiltersAndNamedTrackersWith5MinuteResolution_AggreagetedResultsMatchForPartialFiltersWithMultipleRecordsDefaultResolution() { var filter1 = new CustomerFilter { Environment_ServerName = "Env1", Gender = "M", State = "CA", StoreID = Guid.NewGuid().ToString("D") }; Configurator.Initialize( new Settings { Persister = new PersistToMongo("mongodb://localhost:9001/Graphene"), ReportGenerator = new MongoReportGenerator("mongodb://localhost:9001/Graphene") } ); Container<PerformanceTracker>.Where(filter1).IncrementBy(10); Configurator.ShutDown(); AggregationResults<PerformanceTracker> report = Container<PerformanceTracker>.Where(new CustomerFilter { Gender = "M", }).Report(DateTime.UtcNow.Subtract(new TimeSpan(5000, 1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0))); Assert.IsTrue(report.Results.Count() >= 1); Assert.AreEqual(DateTime.Now.Year, report.Results[0].MesurementTimeUtc.Year); Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Month); Assert.AreEqual(1, report.Results[0].MesurementTimeUtc.Day); Assert.AreEqual(0, report.Results[0].MesurementTimeUtc.Minute); Assert.AreEqual(0, report.Results[0].MesurementTimeUtc.Hour); Assert.AreEqual(ReportResolution.Year, report.Resolution); }
public async Task <ActionResult <List <Contract_CustomerDTO> > > FilterListCustomer([FromBody] Contract_CustomerFilterDTO Contract_CustomerFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFilter CustomerFilter = new CustomerFilter(); CustomerFilter.Skip = 0; CustomerFilter.Take = 20; CustomerFilter.OrderBy = CustomerOrder.Id; CustomerFilter.OrderType = OrderType.ASC; CustomerFilter.Selects = CustomerSelect.ALL; CustomerFilter.Id = Contract_CustomerFilterDTO.Id; CustomerFilter.Code = Contract_CustomerFilterDTO.Code; CustomerFilter.StatusId = Contract_CustomerFilterDTO.StatusId; CustomerFilter.Phone = Contract_CustomerFilterDTO.Phone; CustomerFilter.Address = Contract_CustomerFilterDTO.Address; CustomerFilter.Name = Contract_CustomerFilterDTO.Name; CustomerFilter.Email = Contract_CustomerFilterDTO.Email; CustomerFilter.CustomerTypeId = Contract_CustomerFilterDTO.CustomerTypeId; List <Customer> Customers = await CustomerService.List(CustomerFilter); List <Contract_CustomerDTO> Contract_CustomerDTOs = Customers .Select(x => new Contract_CustomerDTO(x)).ToList(); return(Contract_CustomerDTOs); }
public async Task <List <Ticket_CustomerDTO> > FilterListCustomer([FromBody] Ticket_CustomerFilterDTO Ticket_CustomerFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFilter CustomerFilter = new CustomerFilter(); CustomerFilter.Skip = 0; CustomerFilter.Take = 20; CustomerFilter.OrderBy = CustomerOrder.Id; CustomerFilter.OrderType = OrderType.ASC; CustomerFilter.Selects = CustomerSelect.ALL; CustomerFilter.Id = Ticket_CustomerFilterDTO.Id; CustomerFilter.Code = Ticket_CustomerFilterDTO.Code; List <Customer> Customers = await CustomerService.List(CustomerFilter); List <Ticket_CustomerDTO> Ticket_CustomerDTOs = Customers .Select(x => new Ticket_CustomerDTO(x)).ToList(); return(Ticket_CustomerDTOs); }
public IActionResult GetCustomers([FromBody] CustomerFilter filter) { filter.OrganisationId = customerService.OrganisationId; return(Ok(customerService.GetCustomers(filter))); }
private IQueryable <CustomerDAO> DynamicOrder(IQueryable <CustomerDAO> query, CustomerFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case CustomerOrder.Id: query = query.OrderBy(q => q.Id); break; case CustomerOrder.Username: query = query.OrderBy(q => q.Username); break; case CustomerOrder.DisplayName: query = query.OrderBy(q => q.DisplayName); break; case CustomerOrder.PhoneNumber: query = query.OrderBy(q => q.PhoneNumber); break; case CustomerOrder.Email: query = query.OrderBy(q => q.Email); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case CustomerOrder.Id: query = query.OrderByDescending(q => q.Id); break; case CustomerOrder.Username: query = query.OrderByDescending(q => q.Username); break; case CustomerOrder.DisplayName: query = query.OrderByDescending(q => q.DisplayName); break; case CustomerOrder.PhoneNumber: query = query.OrderByDescending(q => q.PhoneNumber); break; case CustomerOrder.Email: query = query.OrderByDescending(q => q.Email); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
public IActionResult Index(CustomerFilter customerFilter) { ViewBag.Customers = _customerService.GetCustomers(customerFilter, User.IsInRole("Administrator"), User.Identity.GetUserId()); LoadDropdownData(); return(View(customerFilter)); }
public async Task <ActionResult> Export([FromBody] CustomerFeedback_CustomerFeedbackFilterDTO CustomerFeedback_CustomerFeedbackFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } MemoryStream memoryStream = new MemoryStream(); using (ExcelPackage excel = new ExcelPackage(memoryStream)) { #region CustomerFeedback var CustomerFeedbackFilter = ConvertFilterDTOToFilterEntity(CustomerFeedback_CustomerFeedbackFilterDTO); CustomerFeedbackFilter.Skip = 0; CustomerFeedbackFilter.Take = int.MaxValue; CustomerFeedbackFilter = await CustomerFeedbackService.ToFilter(CustomerFeedbackFilter); List <CustomerFeedback> CustomerFeedbacks = await CustomerFeedbackService.List(CustomerFeedbackFilter); var CustomerFeedbackHeaders = new List <string[]>() { new string[] { "Id", "IsSystemCustomer", "CustomerId", "FullName", "Email", "PhoneNumber", "CustomerFeedbackTypeId", "Title", "SendDate", "Content", "StatusId", } }; List <object[]> CustomerFeedbackData = new List <object[]>(); for (int i = 0; i < CustomerFeedbacks.Count; i++) { var CustomerFeedback = CustomerFeedbacks[i]; CustomerFeedbackData.Add(new Object[] { CustomerFeedback.Id, CustomerFeedback.IsSystemCustomer, CustomerFeedback.CustomerId, CustomerFeedback.FullName, CustomerFeedback.Email, CustomerFeedback.PhoneNumber, CustomerFeedback.CustomerFeedbackTypeId, CustomerFeedback.Title, CustomerFeedback.SendDate, CustomerFeedback.Content, CustomerFeedback.StatusId, }); } excel.GenerateWorksheet("CustomerFeedback", CustomerFeedbackHeaders, CustomerFeedbackData); #endregion #region Customer var CustomerFilter = new CustomerFilter(); CustomerFilter.Selects = CustomerSelect.ALL; CustomerFilter.OrderBy = CustomerOrder.Id; CustomerFilter.OrderType = OrderType.ASC; CustomerFilter.Skip = 0; CustomerFilter.Take = int.MaxValue; List <Customer> Customers = await CustomerService.List(CustomerFilter); var CustomerHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", "Phone", "Address", "NationId", "ProvinceId", "DistrictId", "WardId", "CustomerTypeId", "Birthday", "Email", "ProfessionId", "CustomerResourceId", "SexId", "StatusId", "CompanyId", "ParentCompanyId", "TaxCode", "Fax", "Website", "NumberOfEmployee", "BusinessTypeId", "Investment", "RevenueAnnual", "IsSupplier", "Descreption", "Used", "RowId", } }; List <object[]> CustomerData = new List <object[]>(); for (int i = 0; i < Customers.Count; i++) { var Customer = Customers[i]; CustomerData.Add(new Object[] { Customer.Id, Customer.Code, Customer.Name, Customer.Phone, Customer.Address, Customer.NationId, Customer.ProvinceId, Customer.DistrictId, Customer.WardId, Customer.CustomerTypeId, Customer.Birthday, Customer.Email, Customer.ProfessionId, Customer.CustomerResourceId, Customer.SexId, Customer.StatusId, Customer.CompanyId, Customer.ParentCompanyId, Customer.TaxCode, Customer.Fax, Customer.Website, Customer.NumberOfEmployee, Customer.BusinessTypeId, Customer.Investment, Customer.RevenueAnnual, Customer.IsSupplier, Customer.Descreption, Customer.Used, Customer.RowId, }); } excel.GenerateWorksheet("Customer", CustomerHeaders, CustomerData); #endregion #region CustomerFeedbackType var CustomerFeedbackTypeFilter = new CustomerFeedbackTypeFilter(); CustomerFeedbackTypeFilter.Selects = CustomerFeedbackTypeSelect.ALL; CustomerFeedbackTypeFilter.OrderBy = CustomerFeedbackTypeOrder.Id; CustomerFeedbackTypeFilter.OrderType = OrderType.ASC; CustomerFeedbackTypeFilter.Skip = 0; CustomerFeedbackTypeFilter.Take = int.MaxValue; List <CustomerFeedbackType> CustomerFeedbackTypes = await CustomerFeedbackTypeService.List(CustomerFeedbackTypeFilter); var CustomerFeedbackTypeHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", } }; List <object[]> CustomerFeedbackTypeData = new List <object[]>(); for (int i = 0; i < CustomerFeedbackTypes.Count; i++) { var CustomerFeedbackType = CustomerFeedbackTypes[i]; CustomerFeedbackTypeData.Add(new Object[] { CustomerFeedbackType.Id, CustomerFeedbackType.Code, CustomerFeedbackType.Name, }); } excel.GenerateWorksheet("CustomerFeedbackType", CustomerFeedbackTypeHeaders, CustomerFeedbackTypeData); #endregion #region Status var StatusFilter = new StatusFilter(); StatusFilter.Selects = StatusSelect.ALL; StatusFilter.OrderBy = StatusOrder.Id; StatusFilter.OrderType = OrderType.ASC; StatusFilter.Skip = 0; StatusFilter.Take = int.MaxValue; List <Status> Statuses = await StatusService.List(StatusFilter); var StatusHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", } }; List <object[]> StatusData = new List <object[]>(); for (int i = 0; i < Statuses.Count; i++) { var Status = Statuses[i]; StatusData.Add(new Object[] { Status.Id, Status.Code, Status.Name, }); } excel.GenerateWorksheet("Status", StatusHeaders, StatusData); #endregion excel.Save(); } return(File(memoryStream.ToArray(), "application/octet-stream", "CustomerFeedback.xlsx")); }
private async Task <List <Customer> > DynamicSelect(IQueryable <CustomerDAO> query, CustomerFilter filter) { List <Customer> Customers = await query.Select(q => new Customer() { Id = filter.Selects.Contains(CustomerSelect.Id) ? q.Id : default(long), Username = filter.Selects.Contains(CustomerSelect.Username) ? q.Username : default(string), DisplayName = filter.Selects.Contains(CustomerSelect.DisplayName) ? q.DisplayName : default(string), PhoneNumber = filter.Selects.Contains(CustomerSelect.PhoneNumber) ? q.PhoneNumber : default(string), Email = filter.Selects.Contains(CustomerSelect.Email) ? q.Email : default(string), }).ToListAsync(); return(Customers); }
// copy constructor public CustomerFilter(CustomerFilter other) { MinAge = other.MinAge; }
/// <summary> /// Gets customers that meet criterias given in filter /// </summary> /// <param name="filter">filter by which filters</param> /// <param name="requestedPage">page to be given</param> /// <returns></returns> CustomerListQueryResultDTO ListCustomersByFilter(CustomerFilter filter, int requestedPage) { return(customerService.ListCustomersByFilter(filter, requestedPage)); }
static ICollection <Customer> GetCustomers(ICollection <Customer> customerCollection, CustomerFilter filter) { List <Customer> result = new List <Customer>(); foreach (Customer item in customerCollection) { if (filter(item) == true) { result.Add(item); } } return(result); }
static void Main(string[] args) { Customer[] array = new Customer[5]; array[0] = new Customer("Snir Yacoby", 100, "Zrubavel 4"); array[1] = new Customer("Aviel Moshe Yosef", 15, "Najara 51"); array[2] = new Customer("Ronen Eliav", 20, "Eshel 24"); array[3] = new Customer("Yossi Yadgar", 5, "Hatizmoret 40"); array[4] = new Customer("Asi Abergel", 7, "Menashe Tselach 12"); CustomerFilter filter = new CustomerFilter(AKFirstLetterFilter); ICollection <Customer> filteredArray = GetCustomers(array, filter); Console.WriteLine("Filter using function\n"); foreach (Customer customer in filteredArray) { Console.WriteLine("Name: " + customer.Name); Console.WriteLine("Id: " + customer.Id); Console.WriteLine("Address: " + customer.Address); Console.WriteLine(); } filteredArray = GetCustomers(array, delegate(Customer customer) { char firstLetter = customer.Name[0]; bool filterAnswer = false; if (firstLetter >= 'L' && firstLetter <= 'Z') { filterAnswer = true; } return(filterAnswer); }); Console.WriteLine("Filter using anonymous delegate\n"); foreach (Customer customer in filteredArray) { Console.WriteLine("Name: " + customer.Name); Console.WriteLine("Id: " + customer.Id); Console.WriteLine("Address: " + customer.Address); Console.WriteLine(); } filteredArray = GetCustomers(array, customer => { bool filterAnswer = false; if (customer.Id < 100) { filterAnswer = true; } return(filterAnswer); }); Console.WriteLine("Filter using lambda expression\n"); foreach (Customer customer in filteredArray) { Console.WriteLine("Name: " + customer.Name); Console.WriteLine("Id: " + customer.Id); Console.WriteLine("Address: " + customer.Address); Console.WriteLine(); } }
public Task <IList <Customer> > Filter(CustomerFilter filter) { return(Execute(new FilterCustomerCommand(filter))); }
/// <summary> /// Lấy danh sách khách hàng có lọc /// </summary> /// <param name="customerFilter">Điều kiện lọc danh sách khách hàng.</param> /// <returns>Danh sách khách hàng.</returns> /// CreatedBy: dbhuan(20/04/2021) public Paging <Customer> GetCustomers(CustomerFilter customerFilter) { FilterValidate(customerFilter); return(_customerRepository.GetCustomers(customerFilter)); }
public void IntegrationTest_GivenFilters_AggreagetedResultsMatch() { var filter1 = new CustomerFilter { Environment_ServerName = "Env1", Gender = "M", State = "CA", StoreID = Guid.NewGuid().ToString("D") }; Configurator.Initialize( new Settings { Persister = new PersistToMongo("mongodb://localhost:9001/Graphene"), ReportGenerator = new MongoReportGenerator("mongodb://localhost:9001/Graphene") } ); Container<CustomerVisitTracker>.Where(filter1).IncrementBy(10); Configurator.ShutDown(); AggregationResults<CustomerVisitTracker> report = Container<CustomerVisitTracker>.Where(filter1) .Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0))); Assert.IsTrue(report.Results.Any()); Assert.AreEqual(1, report.Results[0].Occurrence); Assert.AreEqual(10, report.Results[0].Total); }
public async Task <ActionResult> Export([FromBody] RepairTicket_RepairTicketFilterDTO RepairTicket_RepairTicketFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } MemoryStream memoryStream = new MemoryStream(); using (ExcelPackage excel = new ExcelPackage(memoryStream)) { #region RepairTicket var RepairTicketFilter = ConvertFilterDTOToFilterEntity(RepairTicket_RepairTicketFilterDTO); RepairTicketFilter.Skip = 0; RepairTicketFilter.Take = int.MaxValue; RepairTicketFilter = await RepairTicketService.ToFilter(RepairTicketFilter); List <RepairTicket> RepairTickets = await RepairTicketService.List(RepairTicketFilter); var RepairTicketHeaders = new List <string[]>() { new string[] { "Id", "Code", "OrderId", "OrderCategoryId", "RepairDueDate", "ItemId", "IsRejectRepair", "RejectReason", "DeviceState", "RepairStatusId", "RepairAddess", "ReceiveUser", "ReceiveDate", "RepairDate", "ReturnDate", "RepairSolution", "Note", "RepairCost", "PaymentStatusId", "CustomerId", "CreatorId", } }; List <object[]> RepairTicketData = new List <object[]>(); for (int i = 0; i < RepairTickets.Count; i++) { var RepairTicket = RepairTickets[i]; RepairTicketData.Add(new Object[] { RepairTicket.Id, RepairTicket.Code, RepairTicket.OrderId, RepairTicket.OrderCategoryId, RepairTicket.RepairDueDate, RepairTicket.ItemId, RepairTicket.IsRejectRepair, RepairTicket.RejectReason, RepairTicket.DeviceState, RepairTicket.RepairStatusId, RepairTicket.RepairAddess, RepairTicket.ReceiveUser, RepairTicket.ReceiveDate, RepairTicket.RepairDate, RepairTicket.ReturnDate, RepairTicket.RepairSolution, RepairTicket.Note, RepairTicket.RepairCost, RepairTicket.PaymentStatusId, RepairTicket.CustomerId, RepairTicket.CreatorId, }); } excel.GenerateWorksheet("RepairTicket", RepairTicketHeaders, RepairTicketData); #endregion #region AppUser var AppUserFilter = new AppUserFilter(); AppUserFilter.Selects = AppUserSelect.ALL; AppUserFilter.OrderBy = AppUserOrder.Id; AppUserFilter.OrderType = OrderType.ASC; AppUserFilter.Skip = 0; AppUserFilter.Take = int.MaxValue; List <AppUser> AppUsers = await AppUserService.List(AppUserFilter); var AppUserHeaders = new List <string[]>() { new string[] { "Id", "Username", "DisplayName", "Address", "Email", "Phone", "SexId", "Birthday", "Avatar", "Department", "OrganizationId", "Longitude", "Latitude", "StatusId", "RowId", "Used", } }; List <object[]> AppUserData = new List <object[]>(); for (int i = 0; i < AppUsers.Count; i++) { var AppUser = AppUsers[i]; AppUserData.Add(new Object[] { AppUser.Id, AppUser.Username, AppUser.DisplayName, AppUser.Address, AppUser.Email, AppUser.Phone, AppUser.SexId, AppUser.Birthday, AppUser.Avatar, AppUser.Department, AppUser.OrganizationId, AppUser.Longitude, AppUser.Latitude, AppUser.StatusId, AppUser.RowId, AppUser.Used, }); } excel.GenerateWorksheet("AppUser", AppUserHeaders, AppUserData); #endregion #region Customer var CustomerFilter = new CustomerFilter(); CustomerFilter.Selects = CustomerSelect.ALL; CustomerFilter.OrderBy = CustomerOrder.Id; CustomerFilter.OrderType = OrderType.ASC; CustomerFilter.Skip = 0; CustomerFilter.Take = int.MaxValue; List <Customer> Customers = await CustomerService.List(CustomerFilter); var CustomerHeaders = new List <string[]>() { new string[] { "Id", "Code", "FullName", "Phone", "IdentificationNumber", "Email", "Address", "StatusId", "NationId", "ProvinceId", "DistrictId", "WardId", "CreatorId", "OrganizationId", "ImageId", "ProfessionId", "Used", } }; List <object[]> CustomerData = new List <object[]>(); for (int i = 0; i < Customers.Count; i++) { var Customer = Customers[i]; CustomerData.Add(new Object[] { Customer.Id, Customer.Code, Customer.Name, Customer.Phone, Customer.Email, Customer.Address, Customer.StatusId, Customer.NationId, Customer.ProvinceId, Customer.DistrictId, Customer.WardId, Customer.ProfessionId, Customer.Used, }); } excel.GenerateWorksheet("Customer", CustomerHeaders, CustomerData); #endregion #region Item var ItemFilter = new ItemFilter(); ItemFilter.Selects = ItemSelect.ALL; ItemFilter.OrderBy = ItemOrder.Id; ItemFilter.OrderType = OrderType.ASC; ItemFilter.Skip = 0; ItemFilter.Take = int.MaxValue; List <Item> Items = await ItemService.List(ItemFilter); var ItemHeaders = new List <string[]>() { new string[] { "Id", "ProductId", "Code", "Name", "ScanCode", "SalePrice", "RetailPrice", "StatusId", "Used", "RowId", } }; List <object[]> ItemData = new List <object[]>(); for (int i = 0; i < Items.Count; i++) { var Item = Items[i]; ItemData.Add(new Object[] { Item.Id, Item.ProductId, Item.Code, Item.Name, Item.ScanCode, Item.SalePrice, Item.RetailPrice, Item.StatusId, Item.Used, Item.RowId, }); } excel.GenerateWorksheet("Item", ItemHeaders, ItemData); #endregion #region OrderCategory var OrderCategoryFilter = new OrderCategoryFilter(); OrderCategoryFilter.Selects = OrderCategorySelect.ALL; OrderCategoryFilter.OrderBy = OrderCategoryOrder.Id; OrderCategoryFilter.OrderType = OrderType.ASC; OrderCategoryFilter.Skip = 0; OrderCategoryFilter.Take = int.MaxValue; List <OrderCategory> OrderCategorys = await OrderCategoryService.List(OrderCategoryFilter); var OrderCategoryHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", } }; List <object[]> OrderCategoryData = new List <object[]>(); for (int i = 0; i < OrderCategorys.Count; i++) { var OrderCategory = OrderCategorys[i]; OrderCategoryData.Add(new Object[] { OrderCategory.Id, OrderCategory.Code, OrderCategory.Name, }); } excel.GenerateWorksheet("OrderCategory", OrderCategoryHeaders, OrderCategoryData); #endregion #region PaymentStatus var PaymentStatusFilter = new PaymentStatusFilter(); PaymentStatusFilter.Selects = PaymentStatusSelect.ALL; PaymentStatusFilter.OrderBy = PaymentStatusOrder.Id; PaymentStatusFilter.OrderType = OrderType.ASC; PaymentStatusFilter.Skip = 0; PaymentStatusFilter.Take = int.MaxValue; List <PaymentStatus> PaymentStatuses = await PaymentStatusService.List(PaymentStatusFilter); var PaymentStatusHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", } }; List <object[]> PaymentStatusData = new List <object[]>(); for (int i = 0; i < PaymentStatuses.Count; i++) { var PaymentStatus = PaymentStatuses[i]; PaymentStatusData.Add(new Object[] { PaymentStatus.Id, PaymentStatus.Code, PaymentStatus.Name, }); } excel.GenerateWorksheet("PaymentStatus", PaymentStatusHeaders, PaymentStatusData); #endregion #region RepairStatus var RepairStatusFilter = new RepairStatusFilter(); RepairStatusFilter.Selects = RepairStatusSelect.ALL; RepairStatusFilter.OrderBy = RepairStatusOrder.Id; RepairStatusFilter.OrderType = OrderType.ASC; RepairStatusFilter.Skip = 0; RepairStatusFilter.Take = int.MaxValue; List <RepairStatus> RepairStatuses = await RepairStatusService.List(RepairStatusFilter); var RepairStatusHeaders = new List <string[]>() { new string[] { "Id", "Name", "Code", } }; List <object[]> RepairStatusData = new List <object[]>(); for (int i = 0; i < RepairStatuses.Count; i++) { var RepairStatus = RepairStatuses[i]; RepairStatusData.Add(new Object[] { RepairStatus.Id, RepairStatus.Name, RepairStatus.Code, }); } excel.GenerateWorksheet("RepairStatus", RepairStatusHeaders, RepairStatusData); #endregion excel.Save(); } return(File(memoryStream.ToArray(), "application/octet-stream", "RepairTicket.xlsx")); }
public async Task <ActionResult> Import(IFormFile file) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } AppUserFilter CreatorFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> Creators = await AppUserService.List(CreatorFilter); CustomerFilter CustomerFilter = new CustomerFilter { Skip = 0, Take = int.MaxValue, Selects = CustomerSelect.ALL }; List <Customer> Customers = await CustomerService.List(CustomerFilter); ItemFilter ItemFilter = new ItemFilter { Skip = 0, Take = int.MaxValue, Selects = ItemSelect.ALL }; List <Item> Items = await ItemService.List(ItemFilter); OrderCategoryFilter OrderCategoryFilter = new OrderCategoryFilter { Skip = 0, Take = int.MaxValue, Selects = OrderCategorySelect.ALL }; List <OrderCategory> OrderCategorys = await OrderCategoryService.List(OrderCategoryFilter); PaymentStatusFilter PaymentStatusFilter = new PaymentStatusFilter { Skip = 0, Take = int.MaxValue, Selects = PaymentStatusSelect.ALL }; List <PaymentStatus> PaymentStatuses = await PaymentStatusService.List(PaymentStatusFilter); RepairStatusFilter RepairStatusFilter = new RepairStatusFilter { Skip = 0, Take = int.MaxValue, Selects = RepairStatusSelect.ALL }; List <RepairStatus> RepairStatuses = await RepairStatusService.List(RepairStatusFilter); List <RepairTicket> RepairTickets = new List <RepairTicket>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(RepairTickets)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int CodeColumn = 1 + StartColumn; int OrderIdColumn = 2 + StartColumn; int OrderCategoryIdColumn = 3 + StartColumn; int RepairDueDateColumn = 4 + StartColumn; int ItemIdColumn = 5 + StartColumn; int IsRejectRepairColumn = 6 + StartColumn; int RejectReasonColumn = 7 + StartColumn; int DeviceStateColumn = 8 + StartColumn; int RepairStatusIdColumn = 9 + StartColumn; int RepairAddessColumn = 10 + StartColumn; int ReceiveUserColumn = 11 + StartColumn; int ReceiveDateColumn = 12 + StartColumn; int RepairDateColumn = 13 + StartColumn; int ReturnDateColumn = 14 + StartColumn; int RepairSolutionColumn = 15 + StartColumn; int NoteColumn = 16 + StartColumn; int RepairCostColumn = 17 + StartColumn; int PaymentStatusIdColumn = 18 + StartColumn; int CustomerIdColumn = 19 + StartColumn; int CreatorIdColumn = 20 + StartColumn; for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++) { if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString())) { break; } string IdValue = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString(); string CodeValue = worksheet.Cells[i + StartRow, CodeColumn].Value?.ToString(); string OrderIdValue = worksheet.Cells[i + StartRow, OrderIdColumn].Value?.ToString(); string OrderCategoryIdValue = worksheet.Cells[i + StartRow, OrderCategoryIdColumn].Value?.ToString(); string RepairDueDateValue = worksheet.Cells[i + StartRow, RepairDueDateColumn].Value?.ToString(); string ItemIdValue = worksheet.Cells[i + StartRow, ItemIdColumn].Value?.ToString(); string IsRejectRepairValue = worksheet.Cells[i + StartRow, IsRejectRepairColumn].Value?.ToString(); string RejectReasonValue = worksheet.Cells[i + StartRow, RejectReasonColumn].Value?.ToString(); string DeviceStateValue = worksheet.Cells[i + StartRow, DeviceStateColumn].Value?.ToString(); string RepairStatusIdValue = worksheet.Cells[i + StartRow, RepairStatusIdColumn].Value?.ToString(); string RepairAddessValue = worksheet.Cells[i + StartRow, RepairAddessColumn].Value?.ToString(); string ReceiveUserValue = worksheet.Cells[i + StartRow, ReceiveUserColumn].Value?.ToString(); string ReceiveDateValue = worksheet.Cells[i + StartRow, ReceiveDateColumn].Value?.ToString(); string RepairDateValue = worksheet.Cells[i + StartRow, RepairDateColumn].Value?.ToString(); string ReturnDateValue = worksheet.Cells[i + StartRow, ReturnDateColumn].Value?.ToString(); string RepairSolutionValue = worksheet.Cells[i + StartRow, RepairSolutionColumn].Value?.ToString(); string NoteValue = worksheet.Cells[i + StartRow, NoteColumn].Value?.ToString(); string RepairCostValue = worksheet.Cells[i + StartRow, RepairCostColumn].Value?.ToString(); string PaymentStatusIdValue = worksheet.Cells[i + StartRow, PaymentStatusIdColumn].Value?.ToString(); string CustomerIdValue = worksheet.Cells[i + StartRow, CustomerIdColumn].Value?.ToString(); string CreatorIdValue = worksheet.Cells[i + StartRow, CreatorIdColumn].Value?.ToString(); RepairTicket RepairTicket = new RepairTicket(); RepairTicket.Code = CodeValue; RepairTicket.RepairDueDate = DateTime.TryParse(RepairDueDateValue, out DateTime RepairDueDate) ? RepairDueDate : DateTime.Now; RepairTicket.RejectReason = RejectReasonValue; RepairTicket.DeviceState = DeviceStateValue; RepairTicket.RepairAddess = RepairAddessValue; RepairTicket.ReceiveUser = ReceiveUserValue; RepairTicket.ReceiveDate = DateTime.TryParse(ReceiveDateValue, out DateTime ReceiveDate) ? ReceiveDate : DateTime.Now; RepairTicket.RepairDate = DateTime.TryParse(RepairDateValue, out DateTime RepairDate) ? RepairDate : DateTime.Now; RepairTicket.ReturnDate = DateTime.TryParse(ReturnDateValue, out DateTime ReturnDate) ? ReturnDate : DateTime.Now; RepairTicket.RepairSolution = RepairSolutionValue; RepairTicket.Note = NoteValue; RepairTicket.RepairCost = decimal.TryParse(RepairCostValue, out decimal RepairCost) ? RepairCost : 0; AppUser Creator = Creators.Where(x => x.Id.ToString() == CreatorIdValue).FirstOrDefault(); RepairTicket.CreatorId = Creator == null ? 0 : Creator.Id; RepairTicket.Creator = Creator; Customer Customer = Customers.Where(x => x.Id.ToString() == CustomerIdValue).FirstOrDefault(); RepairTicket.CustomerId = Customer == null ? 0 : Customer.Id; RepairTicket.Customer = Customer; Item Item = Items.Where(x => x.Id.ToString() == ItemIdValue).FirstOrDefault(); RepairTicket.ItemId = Item == null ? 0 : Item.Id; RepairTicket.Item = Item; OrderCategory OrderCategory = OrderCategorys.Where(x => x.Id.ToString() == OrderCategoryIdValue).FirstOrDefault(); RepairTicket.OrderCategoryId = OrderCategory == null ? 0 : OrderCategory.Id; RepairTicket.OrderCategory = OrderCategory; PaymentStatus PaymentStatus = PaymentStatuses.Where(x => x.Id.ToString() == PaymentStatusIdValue).FirstOrDefault(); RepairTicket.PaymentStatusId = PaymentStatus == null ? 0 : PaymentStatus.Id; RepairTicket.PaymentStatus = PaymentStatus; RepairStatus RepairStatus = RepairStatuses.Where(x => x.Id.ToString() == RepairStatusIdValue).FirstOrDefault(); RepairTicket.RepairStatusId = RepairStatus == null ? 0 : RepairStatus.Id; RepairTicket.RepairStatus = RepairStatus; RepairTickets.Add(RepairTicket); } } RepairTickets = await RepairTicketService.Import(RepairTickets); if (RepairTickets.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < RepairTickets.Count; i++) { RepairTicket RepairTicket = RepairTickets[i]; if (!RepairTicket.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.Id))) { Error += RepairTicket.Errors[nameof(RepairTicket.Id)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.Code))) { Error += RepairTicket.Errors[nameof(RepairTicket.Code)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.OrderId))) { Error += RepairTicket.Errors[nameof(RepairTicket.OrderId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.OrderCategoryId))) { Error += RepairTicket.Errors[nameof(RepairTicket.OrderCategoryId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairDueDate))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairDueDate)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.ItemId))) { Error += RepairTicket.Errors[nameof(RepairTicket.ItemId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.IsRejectRepair))) { Error += RepairTicket.Errors[nameof(RepairTicket.IsRejectRepair)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RejectReason))) { Error += RepairTicket.Errors[nameof(RepairTicket.RejectReason)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.DeviceState))) { Error += RepairTicket.Errors[nameof(RepairTicket.DeviceState)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairStatusId))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairStatusId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairAddess))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairAddess)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.ReceiveUser))) { Error += RepairTicket.Errors[nameof(RepairTicket.ReceiveUser)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.ReceiveDate))) { Error += RepairTicket.Errors[nameof(RepairTicket.ReceiveDate)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairDate))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairDate)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.ReturnDate))) { Error += RepairTicket.Errors[nameof(RepairTicket.ReturnDate)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairSolution))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairSolution)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.Note))) { Error += RepairTicket.Errors[nameof(RepairTicket.Note)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.RepairCost))) { Error += RepairTicket.Errors[nameof(RepairTicket.RepairCost)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.PaymentStatusId))) { Error += RepairTicket.Errors[nameof(RepairTicket.PaymentStatusId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.CustomerId))) { Error += RepairTicket.Errors[nameof(RepairTicket.CustomerId)]; } if (RepairTicket.Errors.ContainsKey(nameof(RepairTicket.CreatorId))) { Error += RepairTicket.Errors[nameof(RepairTicket.CreatorId)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }
public IActionResult GetTotalPages([FromBody] CustomerFilter filter) { filter.OrganisationId = customerService.OrganisationId; customerService.GetTotalPages(filter); return(Ok(filter)); }
static ICollection <Customer> GetCustomers(ICollection <Customer> i_Collection, CustomerFilter i_Filter) { List <Customer> toReturn = new List <Customer>(); foreach (Customer customer in i_Collection) { if (i_Filter(customer)) { toReturn.Add(customer); } } return(toReturn); }
public IEnumerable <Customer> Search(CustomerFilter filter) { return(this.customerRepository.Search(filter)); }
public async Task <ActionResult <Collection <Customer> > > GetCustomers([FromQuery] CustomerFilter filter) { Collection <Customer> result = await customerFacade.Get(filter); return(Ok(result)); }
//You should have used IEnumerable and yield. public static ICollection <Customer> GetCustomers(ICollection <Customer> collection, CustomerFilter filter) { List <Customer> newList = new List <Customer>(); foreach (Customer c in collection) { if (filter(c)) { newList.Add(c); } } return(newList); }
/// <summary> /// Service phân trang,Lọc theo điều kiện /// </summary> /// <param name="customerFilter"> /// Page,PageSize,FullName,PhoneNumber,CustomerGroupId /// </param> /// <returns>PageSize bản ghi của trang Page</returns> /// CreatedBy: KDLong 27/04/2021 public Pagging <Customer> GetCustomers(CustomerFilter customerFilter) { var pagging = _customerRepository.GetCustomers(customerFilter); return(pagging); }
public async Task <ActionResult> Import(IFormFile file) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFilter CustomerFilter = new CustomerFilter { Skip = 0, Take = int.MaxValue, Selects = CustomerSelect.ALL }; List <Customer> Customers = await CustomerService.List(CustomerFilter); CustomerFeedbackTypeFilter CustomerFeedbackTypeFilter = new CustomerFeedbackTypeFilter { Skip = 0, Take = int.MaxValue, Selects = CustomerFeedbackTypeSelect.ALL }; List <CustomerFeedbackType> CustomerFeedbackTypes = await CustomerFeedbackTypeService.List(CustomerFeedbackTypeFilter); StatusFilter StatusFilter = new StatusFilter { Skip = 0, Take = int.MaxValue, Selects = StatusSelect.ALL }; List <Status> Statuses = await StatusService.List(StatusFilter); List <CustomerFeedback> CustomerFeedbacks = new List <CustomerFeedback>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(CustomerFeedbacks)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int IsSystemCustomerColumn = 1 + StartColumn; int CustomerIdColumn = 2 + StartColumn; int FullNameColumn = 3 + StartColumn; int EmailColumn = 4 + StartColumn; int PhoneNumberColumn = 5 + StartColumn; int CustomerFeedbackTypeIdColumn = 6 + StartColumn; int TitleColumn = 7 + StartColumn; int SendDateColumn = 8 + StartColumn; int ContentColumn = 9 + StartColumn; int StatusIdColumn = 10 + StartColumn; for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++) { if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString())) { break; } string IdValue = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString(); string IsSystemCustomerValue = worksheet.Cells[i + StartRow, IsSystemCustomerColumn].Value?.ToString(); string CustomerIdValue = worksheet.Cells[i + StartRow, CustomerIdColumn].Value?.ToString(); string FullNameValue = worksheet.Cells[i + StartRow, FullNameColumn].Value?.ToString(); string EmailValue = worksheet.Cells[i + StartRow, EmailColumn].Value?.ToString(); string PhoneNumberValue = worksheet.Cells[i + StartRow, PhoneNumberColumn].Value?.ToString(); string CustomerFeedbackTypeIdValue = worksheet.Cells[i + StartRow, CustomerFeedbackTypeIdColumn].Value?.ToString(); string TitleValue = worksheet.Cells[i + StartRow, TitleColumn].Value?.ToString(); string SendDateValue = worksheet.Cells[i + StartRow, SendDateColumn].Value?.ToString(); string ContentValue = worksheet.Cells[i + StartRow, ContentColumn].Value?.ToString(); string StatusIdValue = worksheet.Cells[i + StartRow, StatusIdColumn].Value?.ToString(); CustomerFeedback CustomerFeedback = new CustomerFeedback(); CustomerFeedback.FullName = FullNameValue; CustomerFeedback.Email = EmailValue; CustomerFeedback.PhoneNumber = PhoneNumberValue; CustomerFeedback.Title = TitleValue; CustomerFeedback.SendDate = DateTime.TryParse(SendDateValue, out DateTime SendDate) ? SendDate : DateTime.Now; CustomerFeedback.Content = ContentValue; Customer Customer = Customers.Where(x => x.Id.ToString() == CustomerIdValue).FirstOrDefault(); CustomerFeedback.CustomerId = Customer == null ? 0 : Customer.Id; CustomerFeedback.Customer = Customer; CustomerFeedbackType CustomerFeedbackType = CustomerFeedbackTypes.Where(x => x.Id.ToString() == CustomerFeedbackTypeIdValue).FirstOrDefault(); CustomerFeedback.CustomerFeedbackTypeId = CustomerFeedbackType == null ? 0 : CustomerFeedbackType.Id; CustomerFeedback.CustomerFeedbackType = CustomerFeedbackType; Status Status = Statuses.Where(x => x.Id.ToString() == StatusIdValue).FirstOrDefault(); CustomerFeedback.StatusId = Status == null ? 0 : Status.Id; CustomerFeedback.Status = Status; CustomerFeedbacks.Add(CustomerFeedback); } } CustomerFeedbacks = await CustomerFeedbackService.Import(CustomerFeedbacks); if (CustomerFeedbacks.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < CustomerFeedbacks.Count; i++) { CustomerFeedback CustomerFeedback = CustomerFeedbacks[i]; if (!CustomerFeedback.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.Id))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.Id)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.IsSystemCustomer))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.IsSystemCustomer)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.CustomerId))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.CustomerId)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.FullName))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.FullName)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.Email))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.Email)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.PhoneNumber))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.PhoneNumber)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.CustomerFeedbackTypeId))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.CustomerFeedbackTypeId)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.Title))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.Title)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.SendDate))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.SendDate)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.Content))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.Content)]; } if (CustomerFeedback.Errors.ContainsKey(nameof(CustomerFeedback.StatusId))) { Error += CustomerFeedback.Errors[nameof(CustomerFeedback.StatusId)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }
public void IntegrationTest_GivenFiltersAndNamedTrackers_AggreagetedResultsMatchForPartialFilters() { string storeId = Guid.NewGuid().ToString("D"); var filter1 = new CustomerFilter { Environment_ServerName = "Env1", Gender = "M", State = "CA", StoreID = storeId }; Configurator.Initialize( new Settings { Persister = new PersistToMongo("mongodb://localhost:9001/Graphene"), ReportGenerator = new MongoReportGenerator("mongodb://localhost:9001/Graphene") } ); Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 10); Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.KidsCount, 5); Container<TrackerWithCountProperties>.Where(filter1).Increment(t => t.ElderlyCount, 2); Configurator.ShutDown(); AggregationResults<TrackerWithCountProperties> report = Container<TrackerWithCountProperties>.Where(new CustomerFilter { StoreID = storeId }).Report(DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)), DateTime.UtcNow.Add(new TimeSpan(1, 0, 0))); Assert.IsTrue(report.Results.Count() >= 1); Assert.AreEqual(12, report.Results[0].Tracker.ElderlyCount); Assert.AreEqual(5, report.Results[0].Tracker.KidsCount); }
public FilterCustomerCommand(CustomerFilter filter) { _filter = filter; }
/// <summary> /// 分页获取数据 /// </summary> /// <param name="filter"></param> /// <returns></returns> public static IPageOfList <CustomerInfo> GetByFilter(CustomerFilter filter) { return(Dao.GetByFilter(filter)); }
private IQueryable <CustomerDAO> DynamicFilter(IQueryable <CustomerDAO> query, CustomerFilter filter) { if (filter == null) { return(query.Where(q => false)); } if (filter.Id != null) { query = query.Where(q => q.Id, filter.Id); } if (filter.Username != null) { query = query.Where(q => q.Username, filter.Username); } if (filter.DisplayName != null) { query = query.Where(q => q.DisplayName, filter.DisplayName); } if (filter.PhoneNumber != null) { query = query.Where(q => q.PhoneNumber, filter.PhoneNumber); } if (filter.Email != null) { query = query.Where(q => q.Email, filter.Email); } if (filter.Ids != null) { query = query.Where(q => filter.Ids.Contains(q.Id)); } if (filter.ExceptIds != null) { query = query.Where(q => !filter.ExceptIds.Contains(q.Id)); } return(query); }
public IActionResult Customers([FromQuery] CustomerFilter filter) => Ok(dbContext.Customers.ApplyFilter(filter));
static void Main(string[] args) { //////////////////// Lab 7 //////////////////////////////////////////// /* * Customer[] customers = new Customer[7]; * customers[0] = new Customer("Stas", 220, "Yokneam"); * customers[1] = new Customer("Moran", 201, "Ramat-Gan"); * customers[2] = new Customer("Guy", 245, "Ramat-Ilan"); * customers[3] = new Customer("Efrat", 322, "Qiryat-Ono"); * customers[4] = new Customer("Stas", 139, "Herzelia"); * customers[5] = new Customer("Stas", 220, "Herzelia"); * customers[6] = new Customer("Stas", 220, "Herzelia"); * * int index = 0; * foreach (Customer customer in customers) * { * Console.WriteLine((index++) + ") "+customer.ToString()); * } * * Console.Write("\nIs customers[5] & customers[6] is equal? "); * Console.WriteLine(customers[5].Equals(customers[6])); * Console.Write("Is customers[4] & customers[6] is equal? "); * Console.WriteLine(customers[4].Equals(customers[6])); * Console.Write("Is customers[0] & customers[6] is equal? "); * Console.WriteLine(customers[0].Equals(customers[6])); * * Array.Sort(customers); * Console.WriteLine("\nAfter sort:"); * * foreach (Customer customer in customers) * { * Console.WriteLine(customer.ToString()); * } * * AnotherCustomerComparer comparer = new AnotherCustomerComparer(); * * Array.Sort(customers, comparer); * * Console.WriteLine("\nAfter sort with comparer:"); * foreach (Customer customer in customers) * { * Console.WriteLine(customer.ToString()); * } * */ //////////////////// Lab 8 //////////////////////////////////////////// // 5) a. Create a list or array of Customer objects. Customer[] customers = new Customer[8]; customers[0] = new Customer("Stas", 220, "Yokneam"); customers[1] = new Customer("Moran", 91, "Ramat-Gan"); customers[2] = new Customer("Guy", 245, "Ramat-Ilan"); customers[3] = new Customer("Efrat", 322, "Qiryat-Ono"); customers[4] = new Customer("Alex", 139, "Herzelia"); customers[5] = new Customer("Yarin", 22, "Herzelia"); customers[6] = new Customer("Liron", 1100, "Bat-Yam"); customers[7] = new Customer("Ziv", 400, "Tel-Aviv"); List <Customer> list; // 5) b. Create a delegate of type CustomerFilter that should return *true* if its name starts with the letters A-K. // Use a separate method to implement the delegate. CustomerFilter delegate_b = new CustomerFilter(get_AtoK_caustomers); // 5) c. Call GetCustomers with the delegate you created in (b) and display the result. list = GetCustomers(customers, delegate_b); //display results Console.WriteLine("\nA-K results:"); foreach (Customer c in list) { Console.WriteLine(c.ToString()); } // 5) d. Create another such delegate that returns all customers whose names begin with the letters L-Z. Use an anonymous delegate. CustomerFilter delegete_d = delegate(Customer cs) { //letters L-Z char firstChar = cs.Name.ToCharArray()[0]; if ((firstChar >= 'L' && firstChar <= 'Z') || (firstChar >= 'l' && firstChar <= 'z')) { return(true); } return(false); }; // 5) e. Call GetCustomers again with the new delegate and display the results. list = GetCustomers(customers, delegete_d); //display results Console.WriteLine("\nL-Z results:"); foreach (Customer c in list) { Console.WriteLine(c.ToString()); } // 5) f. Create another such delegate that returns all customers whose ID is less than 100. Use a lambda expression. CustomerFilter delegete_f = n => { // ID is less than 100 if (n.ID < 100) { return(true); } return(false); }; // 5) g. Call GetCustomers again with the new delegate and display the results. list = GetCustomers(customers, delegete_f); //display results Console.WriteLine("\n<100 results:"); foreach (Customer c in list) { Console.WriteLine(c.ToString()); } } //************************ end main method ************************ //
public async Task CustomerRepository_List_Test(IEnumerable <Customer> customers, CustomerFilter filter, IEnumerable <Guid> expected) { foreach (var v in customers) { _context.Customers.Add(v); } await _context.SaveChangesAsync(); var repository = new CustomerRepository(_context); var result = await repository.List(filter); result.Select(x => x.Id).ShouldBe(expected, true); }
public Pagging <Customer> GetCustomers(CustomerFilter filter) { return(_customerRepository.GetCustomers(filter)); }
public static ICollection <Customer> GetCustomers(ICollection <Customer> customers, CustomerFilter customerFilter) { List <Customer> filterListCustomers = new List <Customer>(); if (customerFilter != null) { foreach (Customer customer in customers) { if (customerFilter(customer)) { filterListCustomers.Add(customer); } } } return(filterListCustomers); }