Пример #1
0
        public ActionResult Search(IndexHomeModel model)
        {
            IndexHomeModel objIndexHomeModel = new IndexHomeModel();
            try
            {
                List<CarSellerVehicleInfo> searchList = null;
                decimal minPrice = Convert.ToDecimal(model.minPrice);
                decimal maxPrice = Convert.ToDecimal(model.maxPrice);

                List<CarDetailsModel> carDetailsModelList = new List<CarDetailsModel>();

                List<Make> makeModelList = new List<Make>();
                List<CarModel> carModelList = new List<CarModel>();
                List<BodyType> bodyTypeList = new List<BodyType>();
                List<CarSellerType> carSellerTypeList = new List<CarSellerType>();
                List<TransmissionType> transmissionTypeList = new List<TransmissionType>();
                List<FuelType> fuelTypeList = new List<FuelType>();
                List<CarSellingOn> carSellingOnList = new List<CarSellingOn>();

                //CarDetailsSearchModel obj = new CarDetailsSearchModel();
                //obj.BodyTypeName = model.MakeName;
                //list.Add(obj);
                //list.Add(model.MakeName);
                //list.Add(model.ModelName);
                //list.Add(model.CarSellerTypeName);
                //list.Add(model.BodyTypeName);
                //list.Add(model.TransmissionName);
                //list.Add(model.FuelTypeName);
                //list.Add(model.SearchText);

                List<String> list = new List<String>();
                list.Add(model.MakeName);
                list.Add(model.ModelName);
                list.Add(model.CarSellerTypeName);
                list.Add(model.BodyTypeName);
                list.Add(model.TransmissionName);
                list.Add(model.FuelTypeName);
                list.Add(model.SearchText);

                //ArrayList list = new ArrayList();
                //list.Add(model.MakeName);
                //list.Add(model.ModelName);
                //list.Add(model.CarSellerTypeName);
                //list.Add(model.BodyTypeName);
                //list.Add(model.TransmissionName);
                //list.Add(model.FuelTypeName);

                searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(p => list.Any(p2 => p2.Contains(p.Make.Makename) && p2.Contains(p.Model.Modelname) && p2.Contains(p.BodyType.Type) && p2.Contains(p.TransmissionType.Type) && p2.Contains(p.Price.ToString()))).ToList();

                //searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(p => !list.Contains(p.Make.Makename) && !list.Contains(p.Model.Modelname) && !list.Contains(p.BodyType.ToString()) && !list.Contains(p.TransmissionType.ToString()) && !list.Contains(p.FuelType.ToString()) && !list.Contains(p.Price.ToString())).ToList();

                //searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(p => !list.Contains(p.Make.Makename) && !list.Contains(p.Model.Modelname) && !list.Contains(p.BodyType.ToString()) && !list.Contains(p.TransmissionType.ToString()) && !list.Contains(p.FuelType.ToString()) && !list.Contains(p.Price.ToString())).ToList();

                //if (!(string.IsNullOrEmpty(model.MakeName)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName)).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.ModelName)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Model.Modelname.Contains(model.ModelName)).ToList();

                //}

                ////if (!(string.IsNullOrEmpty(model.CarSellerTypeName)))
                ////{
                ////    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.CarSellerType.Type.Contains(model.CarSellerTypeName) || u.CarSellerType.Type.Contains(model.SearchText)).ToList();

                ////}

                //if (!(string.IsNullOrEmpty(model.BodyTypeName)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.BodyType.Type.Contains(model.BodyTypeName)).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.TransmissionName)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.TransmissionType.Type.Contains(model.TransmissionName)).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.FuelTypeName)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.CarSellerVehicleFuelTypes.Any(c => c.FuelType.Type == model.FuelTypeName)).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.minPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Price >= minPrice).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.maxPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Price <= maxPrice).ToList();

                //}

                //if (!(string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.ModelName)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && u.Model.Modelname.Contains(model.ModelName)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.maxPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && (u.Price <= maxPrice)).ToList();
                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && (u.Price >= minPrice)).ToList();
                //}

                //if ((!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.maxPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Model.Modelname.Contains(model.ModelName)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Model.Modelname.Contains(model.ModelName) && (u.Price >= minPrice)).ToList();
                //}

                //if ((!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Price >= minPrice && u.Price <= maxPrice).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && u.Model.Modelname.Contains(model.ModelName) && (u.Price >= minPrice)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.maxPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && u.Model.Modelname.Contains(model.ModelName) && (u.Price <= maxPrice)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && (u.Price <= maxPrice) && (u.Price >= minPrice)).ToList();
                //}

                //if ((!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.minPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Model.Modelname.Contains(model.ModelName) && (u.Price <= maxPrice) && (u.Price >= minPrice)).ToList();

                //}
                //if ((!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.minPrice)) && (!string.IsNullOrEmpty(model.MakeName)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && (u.Price <= maxPrice) && (u.Price >= minPrice)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.minPrice)) && (!string.IsNullOrEmpty(model.ModelName)))
                //{
                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Model.Modelname.Contains(model.ModelName) && (u.Price <= maxPrice) && (u.Price >= minPrice)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.minPrice)) && (!string.IsNullOrEmpty(model.maxPrice)) && (!string.IsNullOrEmpty(model.TransmissionName)) && (!string.IsNullOrEmpty(model.BodyTypeName)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && u.Model.Modelname.Contains(model.ModelName) && (u.Price >= minPrice && u.Price <= maxPrice)  && u.TransmissionType.Type.Contains(model.TransmissionName) && u.BodyType.Type.Contains(model.BodyTypeName) || u.Make.Makename.Contains(model.SearchText) || u.Model.Modelname.Contains(model.SearchText) || u.TransmissionType.Type.Contains(model.SearchText) || u.BodyType.Type.Contains(model.SearchText)).ToList();

                //}

                //if ((!string.IsNullOrEmpty(model.MakeName)) && (!string.IsNullOrEmpty(model.ModelName)) && (!string.IsNullOrEmpty(model.TransmissionName)) && (!string.IsNullOrEmpty(model.BodyTypeName)) && (!string.IsNullOrEmpty(model.FuelTypeName)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.MakeName) && u.Model.Modelname.Contains(model.ModelName) && u.TransmissionType.Type.Contains(model.TransmissionName) && u.BodyType.Type.Contains(model.BodyTypeName) && u.CarSellerVehicleFuelTypes.Any(c=>c.FuelType.Type == model.FuelTypeName) || (u.Make.Makename.Contains(model.SearchText) || u.Model.Modelname.Contains(model.SearchText) || u.TransmissionType.Type.Contains(model.SearchText) || u.BodyType.Type.Contains(model.SearchText) || u.CarSellerVehicleFuelTypes.Any(c => c.FuelType.Type == model.FuelTypeName)) ).ToList();

                //}

                //if ((string.IsNullOrEmpty(model.MakeName)) && (string.IsNullOrEmpty(model.ModelName)) && (string.IsNullOrEmpty(model.minPrice)) && (string.IsNullOrEmpty(model.maxPrice)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetAllCarSellerVehicleInfo().ToList();

                //}

                //if ((string.IsNullOrEmpty(model.MakeName)) && (string.IsNullOrEmpty(model.ModelName)) && (string.IsNullOrEmpty(model.TransmissionName)) && (string.IsNullOrEmpty(model.BodyTypeName)) && (string.IsNullOrEmpty(model.FuelTypeName)) && (!string.IsNullOrEmpty(model.SearchText)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetCarSellerVehicleInfo().Where(u => u.Make.Makename.Contains(model.SearchText) || u.Model.Modelname.Contains(model.SearchText) || u.TransmissionType.Type.Contains(model.SearchText) || u.BodyType.Type.Contains(model.SearchText) || u.CarSellerVehicleFuelTypes.Any(c => c.FuelType.Type == model.FuelTypeName)).ToList();

                //}

                //if ((string.IsNullOrEmpty(model.MakeName)) && (string.IsNullOrEmpty(model.ModelName)) && (string.IsNullOrEmpty(model.TransmissionName)) && (string.IsNullOrEmpty(model.BodyTypeName)) && (string.IsNullOrEmpty(model.FuelTypeName)) && (string.IsNullOrEmpty(model.SearchText)))
                //{

                //    searchList = _carSellerVehicleInfoService.GetAllCarSellerVehicleInfo().ToList();

                //}

                if (searchList != null)
                {

                    foreach (var item in searchList)
                    {
                        if ((item.Title != null) && (item.Price != null || item.Price != 0) && (item.RegistrationNumber != null) && (item.ExactMileage != null))
                        {
                            //var moreinfo = _carSellerMoreDetailService.GetCarSellerMoreDetailByVehicleID(item.ID);
                            //if (moreinfo != null)
                            //{
                                CarDetailsModel carDetails = new CarDetailsModel();

                                carDetails.Title = item.Title;
                                carDetails.MakeName = item.Make.Makename;
                                carDetails.ModelName = item.Model.Modelname;
                                carDetails.Price = Convert.ToDecimal(item.Price);
                                carDetails.RegistrationNo = item.RegistrationNumber;
                                carDetails.ExactMileage = item.ExactMileage;
                                carDetails.TransmissionType = item.TransmissionType.Type;
                                //carDetails.ContactNumber = item.CarSellerMoreDetails.FirstOrDefault().ContactNumber ?? "";
                                //carDetails.Email = item.CarSellerMoreDetails.FirstOrDefault().ContactEmailID ?? "";

                                List<CarSellerVehicleImage> imginfo = _carSellerVehicleImagesService.GetCarSellerVehicleImageByVehicleID(item.ID).ToList();
                                carDetails.CarImages = imginfo;

                            //    carDetails.CarImages = item.CarSellerVehicleImages.ToList();
                                string fuels = "";
                                foreach (var fuelType in item.CarSellerVehicleFuelTypes)
                                {
                                    fuels += fuelType.FuelType.Type + ",";
                                }
                                carDetails.fuelType = fuels.Trim(',');
                                carDetails.Description = item.Description;
                                carDetailsModelList.Add(carDetails);
                            //}

                        }
                    }
                }
                else
                {

                }
                var makelist = _makeService.GetAllMakes();
                if (makelist != null)
                {

                    foreach (var item1 in makelist)
                    {
                        Make obj = new Make();
                        obj.ID = item1.ID;
                        obj.Makename = item1.Makename;
                        makeModelList.Add(obj);

                    }

                }

                var varBodyTypeList = _bodyTypeService.GetAllBodyTypes();
                if (varBodyTypeList != null)
                {
                    foreach (var item in varBodyTypeList)
                    {
                        BodyType obj = new BodyType();
                        obj.ID = item.ID;
                        obj.Type = item.Type;
                        bodyTypeList.Add(obj);

                    }
                }

                var varCarSellerTypeList = _carSellerTyeService.GetAllCarSellerType();
                if (varCarSellerTypeList != null)
                {
                    foreach (var item in varCarSellerTypeList)
                    {
                        CarSellerType obj = new CarSellerType();
                        obj.ID = item.ID;
                        obj.Type = item.Type;
                        carSellerTypeList.Add(obj);

                    }
                }

                var varTransmissionTypeList = _transmissionTyeService.GetAllTransmissionTypes();
                if (varTransmissionTypeList != null)
                {
                    foreach (var item in varTransmissionTypeList)
                    {
                        TransmissionType obj = new TransmissionType();
                        obj.ID = item.ID;
                        obj.Type = item.Type;
                        transmissionTypeList.Add(obj);

                    }
                }

                var varFuelTypeList = _fuelTypeService.GetAllFuelTypes();
                if (varFuelTypeList != null)
                {
                    foreach (var item in varFuelTypeList)
                    {
                        FuelType obj = new FuelType();
                        obj.ID = item.ID;
                        obj.Type = item.Type;
                        fuelTypeList.Add(obj);

                    }
                }

                var varcarSellingOnList = _carSellingOnService.GetAllCarSellinOn();
                if (varcarSellingOnList != null)
                {
                    foreach (var item in varcarSellingOnList)
                    {
                        CarSellingOn obj = new CarSellingOn();
                        obj.ID = item.ID;
                        obj.Way = item.Way;
                        carSellingOnList.Add(obj);

                    }
                }

                var carModelList1 = _carModelService.GetAllCarModels();
                if (carModelList1 != null)
                {
                    foreach (var item in carModelList1)
                    {
                        CarModel obj = new CarModel();
                        obj.ID = item.ID;
                        obj.Modelname = item.Modelname;
                        obj.MakeID = item.MakeID;
                        carModelList.Add(obj);

                    }
                }

                objIndexHomeModel.CarDetailsList = carDetailsModelList;
                objIndexHomeModel.MakeList = makeModelList;
                objIndexHomeModel.bodyTypeList = bodyTypeList;
                objIndexHomeModel.CarSellerTypeList = carSellerTypeList;
                objIndexHomeModel.transmissionTypeList = transmissionTypeList;
                objIndexHomeModel.fuelTypeList = fuelTypeList;
                objIndexHomeModel.CarSellingOnList = carSellingOnList;
                objIndexHomeModel.ModelList = carModelList;

            }
            catch (Exception ex)
            {
                return RedirectToAction("Index", "Home");
            }
            return View(objIndexHomeModel);
        }
Пример #2
0
        //[Route("CarDetails/Index/{type}/{id}")]
        public ActionResult Index(string type,string id)
        {
            try
            {
                if (!string.IsNullOrEmpty(id))
                {

                    //string IDS = Convert.ToString(CommonHelper.Base64Decode(id) ?? "");
                    //int Id = Convert.ToInt32(id);

                    CarDetailsModel carDetailsModel = new CarDetailsModel();

                    if (type.ToLower() == "carseller")
                    {
                        int Id = Convert.ToInt32(CommonHelper.Base64Decode(id) ?? "");

                        CarSellerVehicleInfo carVehicleDetail = _carsellervehicleinfoService.GetCarSellerVehicleInfoByID(Id);
                        if (carVehicleDetail != null)
                        {

                            carDetailsModel.Price = carVehicleDetail.Price != null ? Convert.ToDecimal(carVehicleDetail.Price) : 0;
                            carDetailsModel.Description = carVehicleDetail.Description ?? "";
                            carDetailsModel.ExactMileage = carVehicleDetail.ExactMileage ?? "";
                            if (carVehicleDetail.CarSellerMoreDetails.Count > 0)
                            {
                                carDetailsModel.ContactNumber = carVehicleDetail.CarSellerMoreDetails.FirstOrDefault().ContactNumber ?? "";
                                carDetailsModel.Email = carVehicleDetail.CarSellerMoreDetails.FirstOrDefault().ContactEmailID;
                            }
                            carDetailsModel.TransmissionType = carVehicleDetail.TransmissionType.Type ?? "";
                            carDetailsModel.MakeName = carVehicleDetail.Make.Makename ?? "";
                            carDetailsModel.ModelName = carVehicleDetail.Model.Modelname ?? "";
                            carDetailsModel.RegistrationNo = carVehicleDetail.RegistrationNumber ?? "";

                            List<CarSellerVehicleFuelType> carSellerVehicleFuelTypes = _carSellerVehicleFuelTypeService.CarSellerVehicleFuelTypeByVehicleID(Convert.ToInt16(Id));
                            foreach (var item in carSellerVehicleFuelTypes)
                            {
                                carDetailsModel.FuelType += item.FuelType.Type + " ,";
                            }
                            carDetailsModel.FuelType = carDetailsModel.FuelType.Remove(carDetailsModel.FuelType.Length - 1);
                            var img = _carSellerVehicleImagesService.GetCarSellerVehicleImageByVehicleID(Id).ToList();
                            if (img != null)
                                carDetailsModel.CarImages = _carSellerVehicleImagesService.GetCarSellerVehicleImageByVehicleID(Id).ToList();
                            else
                                carDetailsModel.CarImages = null;

                            carDetailsModel.carType = type;

                        }
                    }
                    else
                    {
                        long ID = Convert.ToInt64(id);
                        AuctionHouseCarSelling aucVehicleDetail = _auctionHouseAddEditVehicleService.GetAuctionHouseCarSellingByID(ID);
                        string[] tranType = aucVehicleDetail.TransmissionTypeIDs.Split(',');
                        string trans = "";
                        foreach (var item in tranType)
                        {
                            int i = Convert.ToInt32(item);

                            TransmissionType tran1 = _transmissionTypeService.GeTransmissionTypeQueryable().Where(t => t.ID ==i).FirstOrDefault();
                            trans += tran1.Type + ",";
                        }

                        string[] fuelType = aucVehicleDetail.FuelTypeIDs.Split(',');
                        string fuels = "";
                        foreach (var item in fuelType)
                        {
                            int i = Convert.ToInt32(item);

                            FuelType fuel1 = _fuelTypeService.GeFuelTypeQueryable().Where(t => t.ID == i).FirstOrDefault();
                            fuels += fuel1.Type + ",";
                        }

                        string make = aucVehicleDetail.Make.Makename;
                        string model = aucVehicleDetail.Model.Modelname;

                        if (aucVehicleDetail != null)
                        {

                            carDetailsModel.Price = aucVehicleDetail.Reserve != null ? Convert.ToDecimal(aucVehicleDetail.Reserve) : 0;
                            carDetailsModel.Description = aucVehicleDetail.VCARDetails ?? "";
                            carDetailsModel.ExactMileage = aucVehicleDetail.ExactMileage ?? "";

                            carDetailsModel.TransmissionType = trans.Trim(',') ?? "";
                            carDetailsModel.fuelType = fuels.Trim(',') ?? "";
                            carDetailsModel.MakeName = make ?? "";
                            carDetailsModel.ModelName = model ?? "";
                            carDetailsModel.RegistrationNo = aucVehicleDetail.RegistrationNo ?? "";

                            var aucImg = _auctionHouseCarSellingVehicleImagesService.GetAuctionHouseCarSellingVehicleImages().Where(t=>t.AuctionHouseCarSellingID==ID).ToList();
                            if (aucImg != null)
                                carDetailsModel.AucCarImages =aucImg.ToList();

                            else
                                carDetailsModel.AucCarImages = null;

                            carDetailsModel.carType = type;

                        }
                    }
                    return View(carDetailsModel);
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            catch (Exception)
            {
                return RedirectToAction("VehiclesShortlisted", "Buyer");

            }
        }