Example #1
0
        private Listing GetSuper(int id)
        {
            SuperListing s = null;

            Domain.Address.Address a = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Listings_SelectListingByLiId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    s = MapListing <SuperListing>(reader);

                    var utilitiesKvp   = new List <KeyValuePair <int, string> >();
                    string[] utilities = ((UtilityTypes)s.UtilitiesIncluded).ToString().Split(',').ToArray();
                    foreach (string utility in utilities)
                    {
                        int key = (int)Enum.Parse(typeof(UtilityTypes), utility);
                        utilitiesKvp.Add(new KeyValuePair <int, string>(key, utility));
                    }
                    s.Utilities     = utilitiesKvp;
                    s.UtilitiesList = ((UtilityTypes)s.UtilitiesIncluded).ToJsonDictionary();
                }
                else if (set == 1)
                {
                    a          = _addressService.MapAddress(reader, 1);
                    s.Location = a;
                }
            });
            return(s);
        }
Example #2
0
        public void GetBrokenRulesValidInputTest()
        {
            var address = new Domain.Address.Address {
                Country     = "UK",
                City        = "London",
                Street      = "Baker street",
                HouseNumber = "221B"
            };

            var spec   = new AddressCountryRequired();
            var broken = spec.GetBrokenRules(address);

            Assert.IsTrue(!broken.Any());
        }
Example #3
0
        public void GetBrokenRulesMissingCountryTest()
        {
            var address = new Domain.Address.Address {
                Country     = null,
                City        = "London",
                Street      = "Baker street",
                HouseNumber = "221B"
            };

            var spec   = new AddressCountryRequired();
            var broken = spec.GetBrokenRules(address);

            Assert.IsTrue(broken.Any());
            Assert.AreEqual(1, broken.Count());
            Assert.AreEqual(AddressBusinessRules.AddressCountryRequired.Description, broken.First().Description);
        }
Example #4
0
        public PagedList <Domain.Address.Address> GetAllMapListingsAddresses(int pageIndex, int pageSize)
        {
            Domain.Address.Address a = null;
            Listing l = null;

            List <Domain.Address.Address> addressList = null;

            PagedList <Domain.Address.Address> addressPage = null;

            Dictionary <int, List <Listing> > dict = null;

            int totalCount = 0;


            DataProvider.ExecuteCmd(GetConnection, "dbo.Listings_SelectPageByAddressId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@pageindex", pageIndex);
                paramCollection.AddWithValue("@pagesize", pageSize);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    a = _addressService.MapAddressListings <Domain.Address.ListingsAddress>(reader);
                    int startingIndex = 11;

                    if (totalCount == 0)
                    {
                        totalCount = reader.GetSafeInt32(startingIndex++);
                    }

                    if (addressList == null)
                    {
                        addressList = new List <Domain.Address.Address>();
                        addressPage = new PagedList <Domain.Address.Address>(addressList, pageIndex, pageSize, totalCount);
                    }
                    addressList.Add(a);
                }

                else if (set == 1)
                {
                    int addressId = reader.GetSafeInt32(0);

                    l = MapListing <Listing>(reader, 1);

                    if (totalCount == 0)
                    {
                        int startingIndex = 13;
                        totalCount        = reader.GetSafeInt32(startingIndex++);
                    }

                    if (dict == null)
                    {
                        dict = new Dictionary <int, List <Listing> >();
                    }

                    if (!dict.ContainsKey(addressId))
                    {
                        dict[addressId] = new List <Listing>();
                    }

                    if (l != null)
                    {
                        dict[addressId].Add(l);
                    }
                }
            });

            if (dict != null)
            {
                foreach (Domain.Address.ListingsAddress currentAddress in addressList)
                {
                    if (dict.ContainsKey(currentAddress.Id))
                    {
                        currentAddress.Listings = dict[currentAddress.Id];
                    }
                }
            }

            return(addressPage);
        }