Ejemplo n.º 1
0
        public async Task <IActionResult> SearchAllCars(SearchCarParameters scp)
        {
            if (ModelState.IsValid)
            {
                var temp = await carService.SearchAllCars(scp);

                if (temp != null)
                {
                    return(Ok(temp));
                }
                else
                {
                    return(BadRequest(new { Message = "Something went wrong. Please, try again later." }));
                }
            }
            else
            {
                return(BadRequest(new { Message = "Invalid parameters supplied." }));
            }
        }
Ejemplo n.º 2
0
        //Our cars u HTML
        public async Task <IEnumerable <Car> > SearchAllCars(SearchCarParameters scp)
        {
            var temp = await repo.GetAllCars(scp.EnterpriseId);

            List <Car> retValue = new List <Car>();

            foreach (var car in temp)
            {
                if (scp.PriceFrom != "" && scp.PriceFrom != null)
                {
                    if (Int32.Parse(scp.PriceFrom) > car.Price)
                    {
                        continue;
                    }
                }

                if (scp.PriceTo != "" && scp.PriceTo != null)
                {
                    if (Int32.Parse(scp.PriceTo) < car.Price)
                    {
                        continue;
                    }
                }

                if (scp.YearOfProductionFrom != "" && scp.YearOfProductionFrom != null)
                {
                    if (Int32.Parse(scp.YearOfProductionFrom) > car.YearOfProduction)
                    {
                        continue;
                    }
                }

                if (scp.YearOfProductionTo != "" && scp.YearOfProductionTo != null)
                {
                    if (Int32.Parse(scp.YearOfProductionTo) < car.YearOfProduction)
                    {
                        continue;
                    }
                }

                if (scp.NumberOfSeats != "" && scp.NumberOfSeats != null)
                {
                    if (Int32.Parse(scp.NumberOfSeats) != car.NumberOfSeats)
                    {
                        continue;
                    }
                }

                if (scp.FuelType != "" && scp.FuelType != null)
                {
                    if (scp.FuelType.ToLower() != car.FuelType.ToLower())
                    {
                        continue;
                    }
                }

                if (scp.TransmissionType != "" && scp.TransmissionType != null)
                {
                    if (scp.TransmissionType.ToLower() != car.TransmissionType.ToLower())
                    {
                        continue;
                    }
                }

                if (scp.Brand != "" && scp.Brand != null)
                {
                    if (scp.Brand.ToLower() != car.Brand.ToLower())
                    {
                        continue;
                    }
                }

                if (scp.Type != "" && scp.Type != null)
                {
                    if (scp.Type.ToLower() != car.Type.ToLower())
                    {
                        continue;
                    }
                }

                if (scp.Model != "" && scp.Model != null)
                {
                    if (scp.Model.ToLower() != car.Model.ToLower())
                    {
                        continue;
                    }
                }

                retValue.Add(car);
            }

            return(retValue);
        }