private void CreateMockHouses() { using (DatabaseContext context = new DatabaseContext()) { filter = new HouseSearchRequest(); filter.City = "City"; /* * filter.Address = "Adress"; * filter.Price = 0; * filter.Skip = 10; * filter.Street = "Street"; * filter.Take = 10; * filter.TypeRent = true; * filter.ZipCode = "ZipCode"; */ for (int i = 0; i < 10; i++) { House house = DomainMocksFactory.CreateHouse(); house.ModifyCode((i).ToString()); house.AddAddress("my address", "my city", "my country", "my st. number", "zip code"); house.AddCategory("my entry", "my description"); house.AssociateAgent(DomainMocksFactory.CreateAgent()); context.Houses.Add(house); } context.SaveChanges(); } }
public IHttpActionResult GetHouses(HouseSearchRequest search) { //throw new NotImplementedException("To do"); // #01 get the result from projection HouseSearchResponse responseObject = HouseProjections.GetHouseList(search); // #02 send back 200 OK with response return(Ok(responseObject)); }
public async Task <ResponseDTO <PagedList <HouseDTO> > > Search(HouseSearchRequest search) { List <OrderExpression <HouseDTO> > orderExpressionList = new List <OrderExpression <HouseDTO> >(); orderExpressionList.Add(new OrderExpression <HouseDTO>(OrderType.Asc, p => p.Address)); Expression <Func <HouseDTO, bool> > queryFilter = c => true; if (!string.IsNullOrEmpty(search.Code)) { queryFilter = queryFilter.And(p => p.Code.Contains(search.Code)); } if (!string.IsNullOrEmpty(search.Name)) { queryFilter = queryFilter.And(p => p.Name.Contains(search.Name)); } if (!string.IsNullOrEmpty(search.PhoneNumber)) { queryFilter = queryFilter.And(p => p.PhoneNumber.Contains(search.PhoneNumber)); } if (search.HouseTypeId.HasValue) { queryFilter = queryFilter.And(p => p.HouseTypeId == search.HouseTypeId.Value); } if (!string.IsNullOrEmpty(search.Address)) { queryFilter = queryFilter.And(p => p.Address.Contains(search.Address)); } if (search.RowStatus.HasValue) { queryFilter = queryFilter.And(p => p.RowStatus == search.RowStatus); } if (search.HouseStatusId.HasValue) { queryFilter = queryFilter.And(p => p.HouseStatusId == search.HouseStatusId.Value); } var house = await _houseDataAccess.ListPagedAsync(queryFilter, search.Page, search.PageSize, orderExpressionList.ToArray()); var pagedResult = new PagedList <HouseDTO>() { Items = house.Items, PageSize = house.PageSize, Page = house.Page, Total = house.Total }; return(ResponseBuilder.Correct(pagedResult)); }
public async Task <ResponseDTO <PagedList <HouseDTO> > > Search([FromUri] HouseSearchRequest search) { var resp = await _houseApplicationService.Search(search); return(resp); }
public static HouseSearchResponse GetHouseList(HouseSearchRequest filter) { using (DatabaseContext context = new DatabaseContext()) { HouseSearchResponse houseSearchResponse = new HouseSearchResponse(); #if DEBUG context.Database.Log = delegate(string s) { Debug.WriteLine(s); }; #endif // #01 get IQueryable with filter applied, not paging yet var result = context.Houses; if (!string.IsNullOrEmpty(filter.City)) { result.Where(x => x.Address.City.Contains(filter.City)).Where(x => x.Rent.Equals(filter.TypeRent)); } if (!string.IsNullOrEmpty(filter.Street)) { result.Where(x => x.Address.Address2.Contains(filter.Street)).Where(x => x.Rent.Equals(filter.TypeRent)); } if (!string.IsNullOrEmpty(filter.Address)) { result.Where(x => x.Address.Address1.Contains(filter.Address)).Where(x => x.Rent.Equals(filter.TypeRent)); } if (!string.IsNullOrEmpty(filter.ZipCode)) { result.Where(x => x.Address.ZipCode.Contains(filter.ZipCode)).Where(x => x.Rent.Equals(filter.TypeRent)); } if (!(filter.Price < 0)) { result.Where(x => x.Price.Equals(filter.Price)).Where(x => x.Rent.Equals(filter.TypeRent)); } // #02 get total count with filter applied var totalRows = result.Count(); // #03 get record using paging var items = result .OrderBy(x => x.Code) .Skip(filter.Skip) .Take(filter.Take) .Select(x => new HouseListItem { Id = x.Id, Code = x.Code, Price = x.Price, Address = x.Address.Address1 + " " + x.Address.Address2 + " " + x.Address.City + " " + x.Address.Country + " " + x.Address.Province }); houseSearchResponse.Items = items.ToList(); houseSearchResponse.TotalRecords = totalRows; return(houseSearchResponse); } }