public ActionResult <QueryResult <CustomerListItem> > Search(string lastname, string customerCode, string voucherID, string phoneNumber, DateTime?birthdate, string shopCode, int pageSize = 20, int pageNumber = 0, bool SortAscending = true) { if (string.IsNullOrWhiteSpace(lastname) && string.IsNullOrWhiteSpace(customerCode) && string.IsNullOrWhiteSpace(voucherID) && string.IsNullOrWhiteSpace(phoneNumber) && !birthdate.HasValue) { throw new Exception("At least one parameter is needed to call this API"); } var predicate = PredicateBuilder.New <CU_B_ADDRESS_BOOK>(true); if (!string.IsNullOrWhiteSpace(lastname)) { predicate = predicate.And(E => E.LASTNAME.StartsWith(lastname)); } if (!string.IsNullOrWhiteSpace(customerCode)) { predicate = predicate.And(E => E.CUSTOMER_CODE == customerCode); } if (!string.IsNullOrWhiteSpace(voucherID)) { predicate = predicate.And(E => E.CU_B_VOUCHER_EXT_AUS.Count(V => V.VOUCHER_ID == voucherID) > 0); } if (!string.IsNullOrWhiteSpace(shopCode)) { predicate = predicate.And(E => E.CU_B_ADDRESS_BOOK_EXT_AUS.SHOP_CODE == shopCode); } if (!string.IsNullOrWhiteSpace(phoneNumber)) { predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE1 == phoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE2 == phoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE3 == phoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.MOBILE == phoneNumber)); } if (birthdate.HasValue) { predicate = predicate.And(E => E.BIRTHDATE == birthdate.Value.Date); } IQueryable <CU_B_ADDRESS_BOOK> qryCustomers = DBContext.CU_B_ADDRESS_BOOK.Include(E => E.CU_B_ADDRESS).Include(E => E.CU_B_VOUCHER_EXT_AUS); int RecordCount = qryCustomers.Where(predicate).Count(); List <CustomerListItem> Result = new List <CustomerListItem>(); if (SortAscending) { qryCustomers = qryCustomers.OrderBy(E => E.LASTNAME).OrderBy(E => E.FIRSTNAME); } else { qryCustomers = qryCustomers.OrderByDescending(E => E.LASTNAME).OrderByDescending(E => E.FIRSTNAME); } foreach (CU_B_ADDRESS_BOOK Item in QueryHelper.GetPageItems <CU_B_ADDRESS_BOOK>(qryCustomers.Where(predicate), pageSize, pageNumber)) { CustomerListItem ResultItem = EntityMapper.Map <CustomerListItem, CU_B_ADDRESS_BOOK>(DBContext, Item, Item.CU_B_ADDRESS_BOOK_EXT_AUS); Result.Add(ResultItem); } return(new QueryResult <CustomerListItem>(pageSize, RecordCount, pageNumber, Result)); }
public CustomerListItem GetCustomerByCurrentUserId() { var entity = _context.Customers.Single(e => e.UserID == _userID); if (entity == null) { return(null); } List <PetListItem> petList = new List <PetListItem>(); foreach (var pet in entity.Pets) { petList.Add(new PetListItem { PetID = pet.PetID, Name = $"{pet.Name}, " }); } var model = new CustomerListItem { PersonID = entity.PersonID, FullName = entity.FullName, PhoneNumber = entity.PhoneNumber, Email = entity.Email, ProfileCreationDate = entity.ProfileCreationDate, Pets = petList, }; return(model); }
public ActionResult <IEnumerable <CustomerListItem> > ByFirstameLastnameBirthdate(string Firstname, string Lastname, DateTime?Birthdate) { if (string.IsNullOrWhiteSpace(Firstname) && string.IsNullOrWhiteSpace(Lastname) && !Birthdate.HasValue) { throw new Exception("At least one parameter is needed to call this API"); } var predicate = PredicateBuilder.New <CU_B_ADDRESS_BOOK>(true); if (!string.IsNullOrWhiteSpace(Firstname)) { predicate = predicate.And(E => E.FIRSTNAME.StartsWith(Firstname)); } if (!string.IsNullOrWhiteSpace(Lastname)) { predicate = predicate.And(E => E.LASTNAME.StartsWith(Lastname)); } if (Birthdate.HasValue) { predicate = predicate.And(E => E.BIRTHDATE == Birthdate.Value.Date); } List <CustomerListItem> Result = new List <CustomerListItem>(); foreach (CU_B_ADDRESS_BOOK Item in DBContext.CU_B_ADDRESS_BOOK.Where(predicate).Take(Settings.Value.MaxQueryResult)) { CustomerListItem ResultItem = EntityMapper.Map <CustomerListItem, CU_B_ADDRESS_BOOK>(DBContext, Item, Item.CU_B_ADDRESS_BOOK_EXT_AUS); Result.Add(ResultItem); } return(Result); }
private void DisplayCustomerDetails(CustomerListItem customerListItem) { var item = customerListItem ?? SelectedCustomer; if (item != null) { _messenger.Send(new DisplayCustomerDetailsMessage(item.Id)); } }
private async Task DeleteCustomer(CustomerListItem customerListItem) { var answer = _dialogService.AskQuestion("Delete customer", "Are you sure to delete the customer '" + customerListItem.FullName + "' ?"); if (answer == Answers.Yes) { await Async(() => _customerListService.DeleteCustomer(customerListItem.Id)); Customers.Remove(customerListItem); } }
public ActionResult <IEnumerable <CustomerListItem> > ByPhoneNumber(string PhoneNumber) { if (string.IsNullOrWhiteSpace(PhoneNumber)) { throw new ArgumentNullException("PhoneNumber"); } var predicate = PredicateBuilder.New <CU_B_ADDRESS_BOOK>(false); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE1 == PhoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE2 == PhoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.PHONE3 == PhoneNumber)); predicate = predicate.Or(E => E.CU_B_ADDRESS.Any(A => A.MOBILE == PhoneNumber)); List <CustomerListItem> Result = new List <CustomerListItem>(); foreach (CU_B_ADDRESS_BOOK Item in DBContext.CU_B_ADDRESS_BOOK.Include(E => E.CU_B_ADDRESS).Where(predicate).Take(Settings.Value.MaxQueryResult)) { CustomerListItem ResultItem = EntityMapper.Map <CustomerListItem, CU_B_ADDRESS_BOOK>(DBContext, Item, Item.CU_B_ADDRESS_BOOK_EXT_AUS); Result.Add(ResultItem); } return(Result); }
/// <summary> /// Adds the customer. /// </summary> /// <param name="currentCustomer">The current customer.</param> public void AddCustomer(Customer currentCustomer) { var newCustomer = new CustomerListItem(currentCustomer); this._customerList.Add(newCustomer); }