public ActionResult GetVehicleDetails(int?typeId, DateTime startDate, DateTime endDate) { VMvehicle _vMvehicle = new VMvehicle(); if (typeId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BO.VehicleDetails _vehicleToConvert = BL.BLVehicle.GetVehicleTypeById((int)typeId); if (_vehicleToConvert == null) { return(HttpNotFound()); } _vMvehicle = ToVMvehicle(_vehicleToConvert, startDate, endDate); //if (Session["pics"]!=null) List <string> _pics = Session["pics"] != null ? (List <string>)Session["pics"] : new List <string>(); if (_pics.Count > 5) { _pics.RemoveAt(0); } _pics.Add(_vMvehicle.PicPath); Session["pics"] = _pics; return(View("VehicleDetails", _vMvehicle)); }
/// <summary> /// Convertit un VehicleDetails vers un VMvehicle. /// </summary> /// <param name="vehicleDetails"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public VMvehicle ToVMvehicle(BO.VehicleDetails vehicleDetails, DateTime startDate, DateTime endDate) { VMvehicle _vMvehicle = new VMvehicle(); _vMvehicle.TypeId = vehicleDetails.VehicleType.Id; _vMvehicle.MakeName = vehicleDetails.VehicleType.MakeName; _vMvehicle.ModelName = vehicleDetails.VehicleType.ModelName; _vMvehicle.PicPath = vehicleDetails.Pictures[0].Path; _vMvehicle.PicLabel = vehicleDetails.Pictures[0].Label; _vMvehicle.DailyPrice = (int)vehicleDetails.DailyPrice; _vMvehicle.StartDate = startDate; _vMvehicle.EndDate = endDate; // _vMvehicle.NDays assigné par .EndDate au niveau du modèle. _vMvehicle.PromoTotal = GetTotalPromo(); _vMvehicle.PriceToPay = _vMvehicle.DailyPrice * _vMvehicle.Ndays - _vMvehicle.PromoTotal >= 0 ? _vMvehicle.DailyPrice * _vMvehicle.Ndays - _vMvehicle.PromoTotal : 0; // Pas de prix négatif (0= gratuit). _vMvehicle.CCName = vehicleDetails.VehicleType.CCName; _vMvehicle.DoorsCount = vehicleDetails.VehicleType.DoorsCount; _vMvehicle.FuelName = vehicleDetails.VehicleType.FuelName; //calcul du total des promos pour chaque véhicule. int GetTotalPromo() { int _promoTotal = 0; List <BO.Promo> _promos = BL.BLPromo.GetPromosForVehicleType(vehicleDetails.VehicleType.Id, vehicleDetails.OfficeName); if (_promos.Count != 0) { byte _totalPercentReduc = 0; int _totalCashReduc = 0; foreach (BO.Promo promo in _promos) { byte _currentPcReduc = _totalPercentReduc; if (promo.PercentReduc != null) { _currentPcReduc += (byte)promo.PercentReduc; } if (_currentPcReduc < 100) { _totalPercentReduc = _currentPcReduc; // max 100% de réduction. } if (promo.FixedReduc != null) { _totalCashReduc += (int)promo.FixedReduc; } } _promoTotal = (_vMvehicle.DailyPrice * _vMvehicle.Ndays) * _totalPercentReduc / 100 + _totalCashReduc; } return(_promoTotal); } return(_vMvehicle); }