/// <summary> /// Calculate the total cost of the rent /// </summary> /// <param name="bikesCount">Number of bikes to rent</param> /// <param name="timeUnit">Time unit of the rent</param> /// <param name="timeValue">Time value</param> /// <param name="prices">List of prices</param> /// <returns>Total cost of the rent</returns> private decimal CalculateTotalCost(int bikesCount, Time.UnitsEnum timeUnit, int timeValue, IList <IPrice> prices) { // Take de price for the timeUnit received var price = prices.FirstOrDefault(p => p.TimeUnit.Equals(timeUnit)); if (price == null) { var errorMessage = string.Format(NoPriceDefinedMessage, timeUnit); throw new ArgumentException(errorMessage, "price"); } return(bikesCount * timeValue * price.Amount); }
/// <summary> /// Initializes a new instance of the <see cref="Rental"/> class. /// </summary> /// <param name="bikesCount">Number of bikes to rent</param> /// <param name="startingAt">Starting date and time</param> /// <param name="timeUnit">Time unit</param> /// <param name="timeValue">Time value</param> /// <param name="prices">List of prices</param> /// <param name="promotions">List of promotions</param> public Rental(int bikesCount, DateTime startingAt, Time.UnitsEnum timeUnit, int timeValue, IList <IPrice> prices, IList <IPromotion> promotions) { Check.NotNull(prices, "prices"); this.BikesCount = Check.NotZeroOrNegative(bikesCount, "bikesCount"); this.StartingAt = startingAt; this.TimeUnit = timeUnit; this.TimeValue = Check.NotZeroOrNegative(timeValue, "timeValue"); this.TotalCost = this.CalculateTotalCost(bikesCount, timeUnit, timeValue, prices); this.TotalDiscount = this.CalculateTotalDiscount(this.TotalCost, bikesCount, promotions); }
/// <summary> /// Initializes a new instance of the <see cref="Rental"/> class with default startingAt date. /// </summary> /// <param name="bikesCount">Number of bikes to rent</param> /// <param name="timeUnit">Time unit</param> /// <param name="timeValue">Time value</param> /// <param name="prices">List of prices</param> /// <param name="promotions">List of promotions</param> public Rental(int bikesCount, Time.UnitsEnum timeUnit, int timeValue, IList <IPrice> prices, IList <IPromotion> promotions) : this(bikesCount, DateTime.UtcNow, timeUnit, timeValue, prices, promotions) { }
/// <summary> /// Initializes a new instance of the <see cref="Price"/> class. /// </summary> /// <param name="timeUnit">Time unit of the price</param> /// <param name="amount">Amount of the price</param> public Price(Time.UnitsEnum timeUnit, decimal amount) { this.TimeUnit = timeUnit; this.Amount = Check.NotNegative(amount, "amount"); }