Пример #1
0
 private IQueryable <Property> PagingRequired(IQueryable <Property> query, PropertyQuery queryObject)
 {
     if (queryObject.Page != 0 || queryObject.PageSize != 0)
     {
         return(query.ApplyPaging(queryObject));
     }
     return(query);
 }
Пример #2
0
 public PropertyQueryInfoViewModel(PropertyQuery model)
 {
     WebServiceName = model.WebServiceName;
     QueryId        = model.QueryId;
     OriginalTitle  = model.Title;
     Title          = model.Title;
     Type           = model.Type;
 }
        public PropertyQueryInfoViewModel(PropertyQuery model, bool use = false)
        {
            WebServiceName = model.WebServiceName;
            QueryId        = model.QueryId;
            OriginalTitle  = model.Title;
            Title          = model.Title;
            Type           = model.Type;

            Use = use;
        }
Пример #4
0
        public ModelCollection <T> ListPropertiesInline <T>(PropertyQuery query, bool getCount = false)
            where T : PropertyEntity
        {
            Select             select   = CreateSelect(query, getCount);
            DataPage <dynamic> dataPage = _modelDataProvider.QueryPage <dynamic>(select);

            return(new ModelCollection <T>(ObjectMapper.MapAll <dynamic, T>(dataPage.Data, config =>
            {
                config.For(x => x.Address).ResolveWith <AddressEntity>();
                config.ForEach(x => x.Files).ResolveWith <FileEntity>();
                config.For(x => x.Branch).ResolveWith <PropertyBranch>();
            }), dataPage.Count));
        }
Пример #5
0
 private IQueryable <Property> SortByRequired(IQueryable <Property> query, PropertyQuery queryObject)
 {
     if (!String.IsNullOrWhiteSpace(queryObject.SortBy))
     {
         var columnsMap = new Dictionary <string, Expression <Func <Property, object> > >()
         {
             ["state"]  = property => property.Suburb.State.Name,
             ["suburb"] = property => property.Suburb.Name
         };
         return(query.ApplyOrdering(queryObject, columnsMap));
     }
     return(query);
 }
        public void CreateSelect()
        {
            // set-up
            PropertyQuery propertyQuery = new PropertyQuery();

            UseFakeConnection();
            A.CallTo(() => _modelDataProvider.NewSelect()).Returns(new Select <Module.Property.Data.DataModel.VProperty>());

            // call
            Select select = _dataProvider.CreateSelect(propertyQuery, false);

            // assert
            select.Sql().MustBe("select top 10 PropertyId,Title,ShortDescription,LongDescription,Cost,PropertyType,OwnershipType,IsCommercial,Status,HasGarden,HasParking,Position,IsStudio,IsFurnished,AddedDate,BedroomCount,BathroomCount,ReceptionCount,Featured,SquareFootage,EntityGuid,LicenseId,AddressId,KnownAs,Address01,Address02,Town,City,PostCode,CountryCode,NameNumber,Latitude,Longitude,BranchGuid,BranchId,Type,DevelopmentId,Name,SystemFileName,FileName from Api.VProperty where (Type=@p0 And Status!=@p1) order by AddedDate");
        }
 public static void AddCountParameters(this DynamicParameters parameters, PropertyQuery query)
 {
     parameters.Add("listingType", (int)query.ListingType);
     parameters.Add("propertyType", (int)query.PropertyType);
     parameters.Add("excludeUnavailable", query.ExcludeUnavailable);
     parameters.Add("isCommercial", query.IsCommercial);
     parameters.Add("postCode", query.Like(x => x.PostCode));
     parameters.Add("minCost", query.MinCost);
     parameters.Add("maxCost", query.MaxCost);
     parameters.Add("minBedrooms", query.MinBedrooms);
     parameters.Add("maxBedrooms", query.MaxBedrooms);
     parameters.Add("orderFlags", (byte)query.Order);
     parameters.Add("keywords", query.Like(x => x.Keywords));
 }
        public void CreateWhereFromQuery()
        {
            // set-up
            PropertyQuery propertyQuery = new PropertyQuery();

            UseFakeConnection();
            A.CallTo(() => _modelDataProvider.NewSelect()).Returns(new Select <Module.Property.Data.DataModel.VProperty>());

            // call
            IWhere where = _dataProvider.CreateWhereFromQuery(propertyQuery);

            // assert
            where.Sql().MustBe("where (Type=@p0 And Status!=@p1)");
            where.Parameters["@p0"].MustBe((byte)0);
        }
Пример #9
0
 private IQueryable <Property> FilteredRequired(IQueryable <Property> query, PropertyQuery queryObject)
 {
     if (queryObject.Available.HasValue)
     {
         query = query.Where(property => property.Available == queryObject.Available);
     }
     if (queryObject.SuburbId.HasValue)
     {
         query = query.Where(property => property.SuburbId == queryObject.SuburbId.Value);
     }
     if (queryObject.StateId.HasValue)
     {
         query = query.Where(property => property.Suburb.StateId == queryObject.StateId.Value);
     }
     return(query);
 }
Пример #10
0
        public async Task <IValue> GetProperty(string name, string?ownerType)
        {
            var propertyQuery = new PropertyQuery
            {
                ElementId = Id,
                Name      = name,
                OwnerType = ownerType ?? ""
            };

            if (await Client.GetPropertyAsync(propertyQuery) is { } reply)
            {
                if (reply.ErrorMessages.Any())
                {
                    throw new Exception(string.Join(Environment.NewLine, reply.ErrorMessages));
                }
                if (reply.PropertyType is { } propertyType)
                {
                    return(new Property(propertyType, reply.ValueType, reply.Value));
                }
                throw new Exception("Property does not have a type specified");
            }
            throw new Exception("Failed to receive a reply");
        }
Пример #11
0
        public Select CreateSelect(PropertyQuery query, bool getCount = false)
        {
            Select <DataModel.VProperty> select = _modelDataProvider.NewSelect();

            IClauseCollection <DataModel.VProperty> where = select
                                                            .Where(x => x.Type, (byte)query.ListingType)
                                                            .And(x => x.PropertyType, query.PropertyType, x => x != PropertyType.All)
                                                            .And(x => x.BedroomCount, SqlOperator.GreaterThanOrEqual, query.MinBedrooms, x => x.HasValue)
                                                            .And(x => x.BedroomCount, SqlOperator.LessThanOrEqual, query.MaxBedrooms, x => x.HasValue)
                                                            .And(x => x.Cost, SqlOperator.GreaterThanOrEqual, query.MinCost, x => x.HasValue)
                                                            .And(x => x.Cost, SqlOperator.LessThanOrEqual, query.MaxCost, x => x.HasValue)
                                                            .And(x => x.PostCode, SqlOperator.Like, query.PostCode, x => !string.IsNullOrEmpty(x))
                                                            .And(x => x.IsCommercial, query.IsCommercial, x => x.GetValueOrDefault(false));


            if (!query.Status.HasFlag(PropertyStatus.Archived))
            {
                where.And(x => x.Status, SqlOperator.NotEqual, PropertyStatus.Archived);
            }

            where.And(x => x.Status, PropertyStatus.Available, x => query.ExcludeUnavailable);

            if (!string.IsNullOrEmpty(query.Keywords))
            {
                where.And()
                .Or(x => x.Address01, SqlOperator.Like, query.Keywords)
                .Or(x => x.Address02, SqlOperator.Like, query.Keywords)
                .Or(x => x.PostCode, SqlOperator.Like, query.Keywords)
                .Or(x => x.Title, SqlOperator.Like, query.Keywords);
            }

            select.IncludeCount(getCount);
            select.Paging(query.Page, query.MaxPerPage);

            return(select);
        }
Пример #12
0
        public ModelCollection <T> ListProperties <T>(PropertyQuery query, bool getCount = false)
            where T : PropertyEntity
        {
            //if(query.Meta.Count == 0)
            //{
            //  return ListPropertiesInline<T>(query, getCount);
            //}

            //string command = "dbo.SPListPropertyQuery";

            string command = query.Meta.Count == 0 ? "dbo.SPListProperty" : "dbo.SPListPropertyQuery";

            return(Query((connection) =>
            {
                IEnumerable <T> data = connection.Query <T, AddressEntity, Marker, FileEntity, PropertyBranch, T>(command, Map, new ListPropertiesParameters(query), commandType: CommandType.StoredProcedure, splitOn: "AddressId,Latitude,SystemFileName,BranchGuid");

                if (getCount)
                {
                    return new ModelCollection <T>(data, GetPropertyCount(query));
                }

                return new ModelCollection <T>(data);
            }));
        }
Пример #13
0
        public async Task <QueryResult <Property> > GetProperties(PropertyQuery queryObject = null)
        {
            var queryResult = new QueryResult <Property>();
            var query       = context.Properties
                              .Include(property => property.Owner)
                              .Include(property => property.Suburb)
                              .ThenInclude(suburb => suburb.State)
                              .Include(property => property.PropertyType)
                              .AsQueryable();

            queryResult.TotalItems = await query.CountAsync();

            if (queryObject != null)
            {
                query = this.FilteredRequired(query, queryObject);
                query = this.SortByRequired(query, queryObject);
                queryResult.TotalItems = await query.CountAsync();

                query = this.PagingRequired(query, queryObject);
            }
            queryResult.Items = await query.ToListAsync();

            return(queryResult);
        }
Пример #14
0
 public IWhere CreateWhereFromQuery(PropertyQuery propertyQuery)
 {
     return(CreateSelect(propertyQuery).Where());
 }
Пример #15
0
        private int GetPropertyCount(PropertyQuery query)
        {
            string command = query.Meta.Count == 0 ? "dbo.SPListProperty_Count" : "dbo.SPListPropertyQuery_Count";

            return(Query <int>(command, new ListPropertiesParameters(query, false)).Single());
        }
 public ListPropertiesParameters(PropertyQuery query, bool includePaging = true)
 {
     _query         = query ?? throw new ArgumentNullException(nameof(query));
     _includePaging = includePaging;
 }