public IActionResult getFastFilteredValues([FromBody] FastFilterDto T)
        {
            var data = publicRepository.GetFastFilteredStock(T);

            if (data != null)
            {
                return(Ok(data));
            }
            else
            {
                return(BadRequest(data));
            }
        }
Example #2
0
        public List <PublicModelDto> GetFastFilteredStock(FastFilterDto T)
        {
            try
            {
                var vacationData           = dc.Vacations.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
                                    });
                                }
                            }
                        }
                    }
                }

                //Starting the filtering of all the stock
                if (T.CountryId != 0)
                {
                    data = data.Where(o => o.CountryId == T.CountryId).ToList();
                }

                if (T.AreaId.Count() != 0)
                {
                    var tempList = new List <PublicModelDto>();
                    foreach (var entity in T.AreaId)
                    {
                        foreach (var subentity in data.Where(o => o.AreaId == entity).ToList())
                        {
                            tempList.Add(subentity);
                        }
                    }
                    data = tempList;
                }

                if (T.Nights != 0)
                {
                    //data = data.Where(o => o.Nights == T.Nights).ToList();
                    data = data.OrderByDescending(o => o.Nights == T.Nights).ToList();
                }

                if (T.Arrival != null)
                {
                    var tempDate = (DateTime)T.Arrival;
                    tempDate = tempDate.Date.AddDays(1);
                    var tempFirst5Dates = data.Where(o => o.Arrival <= tempDate && o.Arrival >= tempDate.AddDays(-5)).ToList();
                    var second5Dates    = data.Where(o => o.Arrival > tempDate && o.Arrival <= tempDate.AddDays(5)).ToList();
                    List <PublicModelDto> first5Dates = new List <PublicModelDto>();
                    foreach (var entity in second5Dates)
                    {
                        tempFirst5Dates.Add(entity);
                    }
                    //var smallestEntity = tempFirst5Dates.Select(o => o.Arrival).Min();
                    data = tempFirst5Dates.OrderBy(o => o.Arrival).ToList();
                }
                return(data);
            }
            catch
            {
                return(null);
            }
        }