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);
        }
Beispiel #3
0
        public HttpResponseMessage GetAllCarsAllData()
        {
            var coll = Request.Headers;
            IEnumerable <string> headerValues = coll.GetValues("page");
            var page = headerValues.FirstOrDefault();

            headerValues = coll.GetValues("carsNum");
            var carsNum = headerValues.FirstOrDefault();

            try
            {
                SearchReturnModel searchReturnModel = searchRepository.GetAllCarsBySearch(new SearchModel(), int.Parse(page), int.Parse(carsNum));
                return(Request.CreateResponse(HttpStatusCode.OK, searchReturnModel));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
        public SearchReturnModel GetAllCarsBySearch(SearchModel searchModel, int page = 0, int carsNum = 0)
        {
            var resultQuary =
                from cars in DB.CARS
                join carTypes in DB.ALLCARTYPES on cars.carTypeID equals carTypes.carTypeID
                join carBranches in DB.BRANCHES on cars.carBranchID equals carBranches.branchID
                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.thisCarType.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,
                carBranchID  = cars.carBranchID,

                carType      = carTypes.thisCarType,
                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);


            var resultSP = DB.GetAllCarsBySearch(carsNum * page, carsNum, searchModel.freeSearch, searchModel.company, searchModel.carType, searchModel.gear, searchModel.year).Select(c => new FullCarDataModel
            {
                carNumber    = c.carNumber,
                carKm        = c.carKm,
                carPicture   = c.carPicture != null ? "/assets/images/cars/" + c.carPicture : null,
                carInShape   = c.carInShape,
                carAvaliable = c.carAvaliable,
                carBranchID  = c.carBranchID,

                carType      = c.thisCarType,
                carFirm      = c.carFirm,
                carModel     = c.carModel,
                carDayPrice  = c.carDayPrice.Value,
                carLatePrice = c.carLatePrice.Value,
                carYear      = c.carYear.Value,
                carGear      = c.carGear,

                branchName    = c.branchName,
                branchAddress = c.branchAddress,
                branchLat     = c.branchLat.Value,
                branchLng     = c.branchLng.Value,

                numerOfCars = c.TotalRows.Value
            });


            if (GlobalVariable.queryType > 0)
            {
                resultQuary = resultSP.AsQueryable();
            }

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

            foreach (FullCarDataModel fullCar in resultQuary)
            {
                if (searchModel.fromDate != null && searchModel.toDate != null)
                {
                    fullCar.carAvaliable = new EntityPriceManager().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();

            if (GlobalVariable.queryType == 0)
            {
                searchReturnModel.fullCarsData      = fullCars;
                searchReturnModel.fullCarsDataLenth = total;
            }
            else
            {
                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);
        }
Beispiel #5
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);
        }