Exemple #1
0
        public SearchReturnModel GetAllCarsBySearch(SearchModel searchModel, int page = 0, int carsNum = 0)
        {
            DataTable dt = new DataTable();
            List <FullCarDataModel> arrFullCars = new List <FullCarDataModel>();

            using (MySqlCommand command = new MySqlCommand())
            {
                dt = GetMultipleQuery(SearchStringsMySql.GetAllCarsBySearch(carsNum * page, carsNum, searchModel.freeSearch, searchModel.company, searchModel.carType, searchModel.gear, searchModel.year));
            }
            foreach (DataRow ms in dt.Rows)
            {
                FullCarDataModel fullCarDataModel = FullCarDataModel.ToObject(ms);
                arrFullCars.Add(fullCarDataModel);
            }

            IEnumerable <FullCarDataModel> query = arrFullCars;

            List <FullCarDataModel> fullCars = new List <FullCarDataModel>();

            foreach (FullCarDataModel fullCar in query)
            {
                if (searchModel.fromDate != null && searchModel.toDate != null)
                {
                    fullCar.carAvaliable = new MySqlPriceManager().CheckIfCarAvaliable(fullCar.carNumber, (DateTime)searchModel.fromDate, (DateTime)searchModel.toDate);
                    if (fullCar.carAvaliable)
                    {
                        fullCar.carPrice = PriceLogic.CarPrice(searchModel.fromDate, searchModel.toDate, fullCar.carDayPrice);
                        fullCars.Add(fullCar);
                    }
                }
                else
                {
                    fullCars.Add(fullCar);
                }
            }

            SearchReturnModel searchReturnModel = new SearchReturnModel();

            searchReturnModel.fullCarsData = fullCars;


            if (searchReturnModel.fullCarsData != null && searchReturnModel.fullCarsData.Count > 0)
            {
                searchReturnModel.fullCarsDataLenth = searchReturnModel.fullCarsData[0].numerOfCars;
            }
            else
            {
                searchReturnModel.fullCarsDataLenth = 0;
            }

            searchReturnModel.fullCarsDataPage = page;
            return(searchReturnModel);
        }
        public static SearchReturnModel ToObject(SqlDataReader reader)
        {
            DataTable dt = new DataTable();

            dt.Load(reader);
            int recordCount = dt.Rows.Count;

            SearchReturnModel searchReturnModel = new SearchReturnModel();

            searchReturnModel.fullCarsDataLenth = int.Parse(reader[recordCount - 2].ToString());
            searchReturnModel.fullCarsDataPage  = int.Parse(reader[recordCount - 1].ToString());

            Debug.WriteLine("searchReturnModel: " + searchReturnModel.ToString());
            return(searchReturnModel);
        }
        public IActionResult GetAllCarsAllData()
        {
            var page    = Request.Headers["page"];
            var carsNum = Request.Headers["carsNum"];

            try
            {
                SearchReturnModel searchReturnModel = searchRepository.GetAllCarsBySearch(new SearchModel(), int.Parse(page), int.Parse(carsNum));
                return(Ok(searchReturnModel));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
Exemple #4
0
        public SearchReturnModel GetAllCarsBySearch(SearchModel searchModel, int page = 0, int carsNum = 0)
        {
            var resultQuary =
                from cars in _cars.AsQueryable()
                join carTypes in _carTypes.AsQueryable() on cars.carTypeIDMongo equals carTypes.carTypeIdMongo
                join carBranches in _branches.AsQueryable() on cars.carBranchIDMongo equals carBranches.branchIDMongo
                where ((searchModel.freeSearch != null && !searchModel.freeSearch.Equals("") && (cars.carNumber.Contains(searchModel.freeSearch) || carTypes.carFirm.Contains(searchModel.freeSearch) || carTypes.carModel.Contains(searchModel.freeSearch))) || (searchModel.freeSearch == null || searchModel.freeSearch.Equals("")))
                where ((searchModel.company != null && !searchModel.company.Equals("") && carTypes.carFirm.Equals(searchModel.company)) || (searchModel.company == null || searchModel.company.Equals("")))
                where ((searchModel.carType != null && !searchModel.carType.Equals("") && carTypes.carType.Equals(searchModel.carType)) || (searchModel.carType == null || searchModel.carType.Equals("")))
                where ((searchModel.gear != null && !searchModel.gear.Equals("") && carTypes.carGear.Equals(searchModel.gear)) || (searchModel.gear == null || searchModel.gear.Equals("")))
                where ((searchModel.year != 0 && carTypes.carYear.Equals(searchModel.year)) || (searchModel.year == 0))

                select new FullCarDataModel
            {
                carNumber        = cars.carNumber,
                carKm            = cars.carKm,
                carPicture       = cars.carPicture != null ? "/assets/images/cars/" + cars.carPicture : null,
                carInShape       = cars.carInShape,
                carAvaliable     = cars.carAvaliable,
                carBranchIDMongo = cars.carBranchIDMongo,

                carType      = carTypes.carType,
                carFirm      = carTypes.carFirm,
                carModel     = carTypes.carModel,
                carDayPrice  = carTypes.carDayPrice,
                carLatePrice = carTypes.carLatePrice,
                carYear      = carTypes.carYear,
                carGear      = carTypes.carGear,

                branchName    = carBranches.branchName,
                branchAddress = carBranches.branchAddress,
                branchLat     = carBranches.branchLat,
                branchLng     = carBranches.branchLng
            };

            var total = resultQuary.Count();

            resultQuary = resultQuary.OrderBy(c => c.carNumber).Skip(page * carsNum).Take(carsNum);


            List <FullCarDataModel> fullCars = new List <FullCarDataModel>();

            foreach (FullCarDataModel fullCar in resultQuary)
            {
                if (searchModel.fromDate != null && searchModel.toDate != null)
                {
                    fullCar.carAvaliable = new MongoPriceManager().CheckIfCarAvaliable(fullCar.carNumber, (DateTime)searchModel.fromDate, (DateTime)searchModel.toDate);
                    if (fullCar.carAvaliable)
                    {
                        fullCar.carPrice = PriceLogic.CarPrice(searchModel.fromDate, searchModel.toDate, fullCar.carDayPrice);
                        fullCars.Add(fullCar);
                    }
                }
                else
                {
                    fullCars.Add(fullCar);
                }
            }

            SearchReturnModel searchReturnModel = new SearchReturnModel();

            searchReturnModel.fullCarsData      = fullCars;
            searchReturnModel.fullCarsDataLenth = total;
            searchReturnModel.fullCarsDataPage  = page;
            return(searchReturnModel);
        }