public IActionResult getFilteredValues([FromBody] PublicFilterDto T)
        {
            var data = publicRepository.GetFilteredStock(T);

            if (data != null)
            {
                return(Ok(data));
            }
            else
            {
                return(BadRequest(data));
            }
        }
Example #2
0
        public List <PublicModelDto> GetFilteredStock(PublicFilterDto T)
        {
            //This method is to first delete all the outdated stock
            CleanVacations();

            try
            {
                var vacationData           = dc.Vacations.Where(o => o.Sold == false).ToList();
                List <PublicModelDto> data = new List <PublicModelDto>();
                Resort  theResort;
                Area    theArea;
                Region  theRegion;
                Country theCountry;
                foreach (var entity in vacationData)
                {
                    //gathering the resort, region, area and country and if null do not add to the list
                    theResort = dc.Resorts.Where(o => o.Id == entity.ResortId).FirstOrDefault();
                    if (theResort != null)
                    {
                        theRegion = dc.Regions.Where(o => o.Id == theResort.RegionId).FirstOrDefault();
                        if (theRegion != null)
                        {
                            theArea = dc.Areas.Where(o => o.Id == theRegion.AreaId).FirstOrDefault();
                            if (theArea != null)
                            {
                                theCountry = dc.Countries.Where(o => o.Id == theArea.CountryId).FirstOrDefault();
                                if (theCountry != null)
                                {
                                    data.Add(new PublicModelDto()
                                    {
                                        Id         = entity.Id,
                                        Resort     = theResort.Description,
                                        ResortId   = entity.ResortId,
                                        Link       = theResort.Link,
                                        RegionId   = theRegion.Id,
                                        Region     = theRegion.Description,
                                        AreaId     = theArea.Id,
                                        Area       = theArea.Description,
                                        CountryId  = theCountry.Id,
                                        Country    = theCountry.Description,
                                        UnitSize   = dc.UnitSizes.Where(o => o.Id == entity.UnitSizeId).FirstOrDefault().Description,
                                        UnitSizeId = entity.UnitSizeId,
                                        Arrival    = entity.Arrival,
                                        Nights     = entity.Nights,
                                        Price2Pay  = entity.Price2Pay,
                                        Sold       = entity.Sold
                                    });
                                }
                            }
                        }
                    }
                }

                //Start filltering the data according to the model
                if (T.ResortId != null)
                {
                    data = data.Where(o => o.ResortId == T.ResortId).ToList();
                }
                if (T.ArrivalIn != null)
                {
                    data = data.Where(o => o.Arrival > T.ArrivalIn).ToList();
                }
                if (T.ArrivalOut != null)
                {
                    data = data.Where(o => o.Arrival < T.ArrivalIn).ToList();
                }
                if (T.MaxAmount != null)
                {
                    data = data.Where(o => o.Price2Pay < T.MaxAmount).ToList();
                }
                if (T.MinAmount != null)
                {
                    data = data.Where(o => o.Price2Pay > T.MinAmount).ToList();
                }
                if (T.RegionId != null)
                {
                    data = data.Where(o => o.RegionId == T.RegionId).ToList();
                }
                if (T.AreaId != null)
                {
                    data = data.Where(o => o.AreaId == T.AreaId).ToList();
                }
                if (T.CountryId != null)
                {
                    data = data.Where(o => o.CountryId == T.CountryId).ToList();
                }
                if (T.UnitSizeId != null)
                {
                    data = data.Where(o => o.UnitSizeId == T.UnitSizeId).ToList();
                }

                //return the filtered data
                return(data);
            }
            catch
            {
                return(null);
            }
        }