public static Neighborhood GetByID(int NeighborhoodID, IEnumerable <string> includeList = null)
        {
            Neighborhood obj = null;
            string       key = cacheKeyPrefix + NeighborhoodID + GetCacheIncludeText(includeList);

            Neighborhood tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as Neighborhood;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <Neighborhood> itemQuery = AddIncludes(entity.Neighborhood, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.NeighborhoodID == NeighborhoodID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
Пример #2
0
        public static List <Neighborhood> NeighborhoodPageForFrontend(int startRowIndex, int maximumRows, string searchText, string sortField, bool sortDirection, Filters filterList = new Filters())
        {
            sortField = (!string.IsNullOrWhiteSpace(sortField) ? sortField : "NeighborhoodID");

            string cachingFilterText = GetCacheFilterText(filterList.GetCustomFilterList(), searchText);

            List <Neighborhood> objects;
            string baseKey  = cacheKeyPrefix + cachingFilterText;
            string key      = baseKey + "_" + sortField + "_" + sortDirection + "_" + startRowIndex + "_" + maximumRows;
            string countKey = baseKey + "_count";

            List <Neighborhood> tmpList = null;
            int?tmpInt = null;

            if (Cache.IsEnabled)
            {
                tmpList = Cache[key] as List <Neighborhood>;
                tmpInt  = Cache[countKey] as int?;
            }

            if (tmpList != null && tmpInt.HasValue)
            {
                objects     = tmpList;
                m_ItemCount = tmpInt.Value;
            }
            else
            {
                int pageNumber = maximumRows > 0 ? 1 + startRowIndex / maximumRows : 1;

                objects = new List <Neighborhood>();
                using (Entities entity = new Entities())
                {
                    var itemQuery = SetupQuery(entity.Neighborhood, "Neighborhood", filterList.GetFilterList(), searchText, m_LikeSearchProperties, sortField, sortDirection).Select(n => new { Neigborhood = n, n.Address, n.Address.State, NumberHomesAvailable = n.ShowcaseItem.Count(s => ((s.NewHome || (n.ShowLotsLand && (s.ShowcaseID == (int)Showcase.MeybohmShowcases.AikenLand || s.ShowcaseID == (int)Showcase.MeybohmShowcases.AugustaLand))) && s.Active && s.Rented == false)) });
                    if (!string.IsNullOrEmpty(filterList.FilterNeighborhoodZip))
                    {
                        itemQuery = itemQuery.Where(n => n.Neigborhood.Address.Zip == filterList.FilterNeighborhoodZip);
                    }
                    var tempList = maximumRows <= 0 ? itemQuery.ToList() : itemQuery.Skip(maximumRows * (pageNumber - 1)).Take(maximumRows).ToList();
                    m_ItemCount = tmpInt.HasValue ? tmpInt.Value : (maximumRows <= 0 || (pageNumber == 1 && tempList.Count < maximumRows) ? tempList.Count : itemQuery.Count());

                    foreach (var n in tempList)
                    {
                        Neighborhood obj = n.Neigborhood;
                        obj.Address              = n.Address;
                        obj.Address.State        = n.State;
                        obj.NumberHomesAvailable = n.NumberHomesAvailable;
                        objects.Add(obj);
                    }
                }

                Cache.Store(key, objects);
                Cache.Store(countKey, m_ItemCount);
            }
            return(objects);
        }
 public Neighborhood(Neighborhood objectToCopy)
 {
     Active         = objectToCopy.Active;
     AddressID      = objectToCopy.AddressID;
     Amenities      = objectToCopy.Amenities;
     CMMicrositeID  = objectToCopy.CMMicrositeID;
     Directions     = objectToCopy.Directions;
     Featured       = objectToCopy.Featured;
     Image          = objectToCopy.Image;
     Name           = objectToCopy.Name;
     NeighborhoodID = objectToCopy.NeighborhoodID;
     Overview       = objectToCopy.Overview;
     Phone          = objectToCopy.Phone;
     PriceRange     = objectToCopy.PriceRange;
     ShowLotsLand   = objectToCopy.ShowLotsLand;
     Website        = objectToCopy.Website;
 }