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 IActionResult GetCarAllData(string number) { try { FullCarDataModel oneFullCarDataModel = fullDataRepository.GetCarAllData(number); return(Ok(oneFullCarDataModel)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(StatusCode(StatusCodes.Status500InternalServerError, errors)); } }
public FullCarDataModel GetCarDayPrice(string carNumber) { DataTable dt = new DataTable(); FullCarDataModel fullCarDataModel = new FullCarDataModel(); using (SqlCommand command = new SqlCommand()) { dt = GetMultipleQuery(SearchStringsSql.GetCarDayPriceBySearch(carNumber)); } foreach (DataRow ms in dt.Rows) { fullCarDataModel.carDayPrice = decimal.Parse(ms[0].ToString()); } return(fullCarDataModel); }
public OrderPriceModel priceForOrderIfAvaliable(OrderPriceModel carForPrice) { bool isAvaliable = CheckIfCarAvaliable(carForPrice.carNumber, carForPrice.rentStartDate, carForPrice.rentEndDate) == true; if (isAvaliable == true) { FullCarDataModel myCarsForRentModel = GetCarDayPrice(carForPrice.carNumber); carForPrice.orderDays = ((carForPrice.rentEndDate - carForPrice.rentStartDate).Days); carForPrice.carPrice = PriceLogic.CarPrice(carForPrice.rentStartDate, carForPrice.rentEndDate, myCarsForRentModel.carDayPrice); } else { throw new DateNotAvaliableException("The Car Is Not Avaliable at this dates"); } return(carForPrice); }
public FullCarDataModel GetCarAllData(string carNumber) { DataTable dt = new DataTable(); FullCarDataModel fullCarDataModel = new FullCarDataModel(); using (MySqlCommand command = new MySqlCommand()) { dt = GetMultipleQuery(SearchStringsMySql.GetCarAllDataBySearch(carNumber)); } foreach (DataRow ms in dt.Rows) { fullCarDataModel = FullCarDataModel.ToObject(ms); } fullCarDataModel.carAvaliable = new MySqlPriceManager().CheckIfCarAvaliable(carNumber, DateTime.Now, DateTime.Now); return(fullCarDataModel); }
public List <FullCarDataModel> GetCarsForRentByUserId(string userID) { if (userID.Equals("")) { throw new ArgumentOutOfRangeException(); } DataTable dt = new DataTable(); List <FullCarDataModel> arrCarsForRent = new List <FullCarDataModel>(); using (MySqlCommand command = new MySqlCommand()) { dt = GetMultipleQuery(CarForRentStringsMySql.GetAllCarsForRentByUserId(userID)); } foreach (DataRow ms in dt.Rows) { arrCarsForRent.Add(FullCarDataModel.ToObject(ms)); } return(arrCarsForRent); }
public static FullCarDataModel ToObject(DataRow reader) { FullCarDataModel fullCarDataModel = new FullCarDataModel(); fullCarDataModel.carNumber = reader[0].ToString(); fullCarDataModel.carKm = double.Parse(reader[1].ToString()); fullCarDataModel.carPicture = reader[2].ToString(); if (!fullCarDataModel.carPicture.Equals(string.Empty) && !fullCarDataModel.carPicture.Equals("")) { fullCarDataModel.carPicture = "/assets/images/cars/" + fullCarDataModel.carPicture; } try { fullCarDataModel.carInShape = int.Parse(reader[3].ToString()) > 0; } catch (Exception ex) { Debug.WriteLine("trying to parse mysql carInShape: " + ex.Message); } try { fullCarDataModel.carInShape = bool.Parse(reader[3].ToString()); } catch (Exception ex) { Debug.WriteLine("trying to parse mssql carInShape: " + ex.Message); } try { fullCarDataModel.carAvaliable = int.Parse(reader[4].ToString()) > 0; } catch (Exception ex) { Debug.WriteLine("trying to parse mysql carAvaliable: " + ex.Message); } try { fullCarDataModel.carAvaliable = bool.Parse(reader[4].ToString()); } catch (Exception ex) { Debug.WriteLine("trying to parse mssql carAvaliable: " + ex.Message); } fullCarDataModel.carBranchID = int.Parse(reader[5].ToString()); fullCarDataModel.carType = reader[6].ToString(); fullCarDataModel.carFirm = reader[7].ToString(); fullCarDataModel.carModel = reader[8].ToString(); fullCarDataModel.carDayPrice = decimal.Parse(reader[9].ToString()); fullCarDataModel.carLatePrice = decimal.Parse(reader[10].ToString()); fullCarDataModel.carYear = int.Parse(reader[11].ToString()); fullCarDataModel.carGear = reader[12].ToString(); fullCarDataModel.branchName = reader[13].ToString(); fullCarDataModel.branchAddress = reader[14].ToString(); fullCarDataModel.branchLat = double.Parse(reader[15].ToString()); fullCarDataModel.branchLng = double.Parse(reader[16].ToString()); try { fullCarDataModel.numerOfCars = int.Parse(reader[17].ToString()); } catch (Exception ex) { Debug.WriteLine("Number Of Cars Exception: " + ex.Message); } Debug.WriteLine("fullCarDataModel: " + fullCarDataModel.ToString()); return(fullCarDataModel); }