Ejemplo n.º 1
0
        public async Task <_ListViewModel <UnitListViewModel> > GetUnits(UnitSearchViewModel search)
        {
            var model = new _ListViewModel <UnitListViewModel>();

            try
            {
                var result = await _context.LoadStoredProc("dbo.apiUnitSearch")
                             .WithSqlParam("ownerType", search.OwnerType)
                             .WithSqlParam("inventoryID", null)
                             .WithSqlParam("resortID", null)
                             .WithSqlParam("startDate", search.CheckInStart)
                             .WithSqlParam("endDate", search.CheckInEnd)
                             .WithSqlParam("regionCode", search.RegionCode)
                             .WithSqlParam("countryCode", search.CountryCode)
                             .WithSqlParam("stateCode", search.StateCode)
                             .WithSqlParam("city", search.City)
                             .WithSqlParam("bedroomSize", (search.BedroomSize.HasValue) ? (int?)search.BedroomSize.Value : null)
                             .WithSqlParam("inventoryType", (search.InventoryType.HasValue) ? search.InventoryType.Value.ToString() : null)
                             .WithSqlParam("maximumRSICost", search.MaximumNetRate)
                             .WithSqlParam("startRowIndex", search.StartRowIndex)
                             .WithSqlParam("numberOfRows", search.NumberOfRows)
                             .WithSqlParam("orderBy", search.SortColumn)
                             .WithSqlParam("orderDirection", search.SortDirection)
                             .ExecuteStoredProcAsync <apiUnitSearchResult>();

                model.Rows = result.Select(u => new UnitListViewModel()
                {
                    Description    = u.description.Replace("\n", " "),
                    ImageURL       = $"http://accessrsi.com/dannoJR/ProductImageHandler.ashx?imageid={u.imageID}",
                    LowestNetRate  = u.lowest,
                    OwnerId        = u.ownerID,
                    OriginalUnitId = u.origionalID,
                    UnitId         = u.unitID,
                    UnitName       = u.unitName,
                    Address        = new AddressViewModel()
                    {
                        City            = u.city,
                        CountryCode     = u.countryCode,
                        CountryFullName = u.countryFullName,
                        PostalCode      = u.postalCode,
                        RegionCode      = u.regionCode,
                        RegionFullName  = u.regionFullName,
                        StateCode       = u.stateCode,
                        StateFullName   = u.stateFullName,
                        StreetAddress   = u.address.Trim()
                    },
                    MaxRows = u.maxrows
                }).ToList();

                model.TotalCount = (model.RowCount > 0) ? model.Rows[0].MaxRows : 0;
                model.Message    = "Success";
            }
            catch (Exception ex)
            {
                model.Message = $"Error: {ex.Message}";
            }

            return(model);
        }
Ejemplo n.º 2
0
        public async Task <_ListViewModel <UnitListViewModel> > Get(OwnerType?ownerType, DateTime?checkInStart, DateTime?checkInEnd,
                                                                    string regionCode, string countryCode, string stateCode, string city, BedroomSize?bedroomSize, InventoryType?inventoryType, decimal?maximumNetRate,
                                                                    int?startRowIndex = 1, int?numberOfRows = 10, string orderBy = "price", string orderDirection = "asc")
        {
            var model = new _ListViewModel <UnitListViewModel>();

            try
            {
                var search = new UnitSearchViewModel()
                {
                    OwnerType      = ownerType,
                    CheckInStart   = checkInStart,
                    CheckInEnd     = checkInEnd,
                    RegionCode     = regionCode,
                    CountryCode    = countryCode,
                    StateCode      = stateCode,
                    City           = city,
                    BedroomSize    = bedroomSize,
                    InventoryType  = inventoryType,
                    MaximumNetRate = maximumNetRate,
                    StartRowIndex  = startRowIndex,
                    NumberOfRows   = numberOfRows,
                    SortColumn     = orderBy,
                    SortDirection  = orderDirection,
                    ExactMatch     = true,
                };

                model = await _context.GetUnits(search);
            }
            catch (Exception ex)
            {
                if (model == null)
                {
                    model = new _ListViewModel <UnitListViewModel>();
                }

                if (model.Message.Length > 0)
                {
                    model.Message += " | ";
                }
                else
                {
                    model.Message = "Error: ";
                }

                model.Message += ex.Message;
            }

            return(model);
        }
Ejemplo n.º 3
0
        public IActionResult SearchResults(UnitSearchViewModel model)
        {
            var filters = new List <Tuple <string, object> >();

            foreach (var property in model.GetType().GetProperties())
            {
                var value = property.GetValue(model);
                if (value == null)
                {
                    continue;
                }

                if (property.PropertyType == typeof(decimal?))
                {
                    if (property.Name.EndsWith("Low"))
                    {
                        filters.Add(new Tuple <string, object>($"{property.Name.Substring(0, property.Name.Length - 3)} > {{0}}", $"{(decimal)value}"));
                    }
                    else
                    {
                        filters.Add(new Tuple <string, object>($"{property.Name.Substring(0, property.Name.Length - 4)} < {{0}}", $"{(decimal)value}"));
                    }
                }

                if (property.PropertyType == typeof(DateTime?))
                {
                    if (property.Name.EndsWith("Start"))
                    {
                        filters.Add(new Tuple <string, object>($"{property.Name.Substring(0, property.Name.Length - 5)} > {{0}}", $"{(DateTime)value}"));
                    }
                    else
                    {
                        filters.Add(new Tuple <string, object>($"{property.Name.Substring(0, property.Name.Length - 3)} < {{0}}", $"{(DateTime)value}"));
                    }
                }

                if (property.PropertyType == typeof(string) && !string.IsNullOrEmpty(value.ToString().Trim()))
                {
                    filters.Add(new Tuple <string, object>($"{property.Name} LIKE {{0}}", $"%{value.ToString()}%"));
                }
            }

            var units = _unitRepository.GetUnits(filters);

            return(View("Index", units));
        }