/* * This same function is used for all of the different Rule Files. All of the Rule Files have the same syntax and format. */ private static void LoadCalculationRules(string filepath, ref List <CalculationRule> calculationRules) { try { //https://stackoverflow.com/questions/5282999/reading-csv-file-and-storing-values-into-an-array //referencing stackoverflow for this specific code because it's almost verbatim. using (var reader = new StreamReader(filepath)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = string.IsNullOrEmpty(line) ? string.Empty.Split(',') : line.Split(','); try { var calculationRule = new CalculationRule(int.Parse(values[0]), int.Parse(values[1]), values[2]); calculationRules.Add(calculationRule); } catch (Exception ex) { Console.WriteLine("There has been an exception trying to parse one of the calculation rules. Please check the file for any errors."); Console.WriteLine(filepath); Console.WriteLine(ex.Message); } } } } catch (Exception ex) { Console.WriteLine("There has been an exception trying to load one of the Rule Files. Please check if the file exists and if permissions are valid."); Console.WriteLine(filepath); Console.WriteLine(ex.Message); } }
public CheckoutAddonItemModel(int id, string name, string description, decimal price, PostingRhythm postingRhythm, CalculationRule calculationRule) { Id = id; Name = name; Description = description; Price = price; PostingRhythm = (int) postingRhythm; CalculationRule = (int) calculationRule; IsSelected = false; }
public static decimal CalculateAddonPrice(decimal price, CalculationRule calculationRule, PostingRhythm postingRhythm, int adults, int children, int babies, int days) { var total = 0.0m; switch (calculationRule) { case CalculationRule.PerPerson: total = (adults + children + babies) * price; break; case CalculationRule.PerAdult: total = adults * price; break; case CalculationRule.PerChild: total = children * price; break; case CalculationRule.PerBaby: total = babies * price; break; case CalculationRule.PerRoom: total = 1 * price; break; default: break; } switch (postingRhythm) { case PostingRhythm.Everyday: total = total * days; break; case PostingRhythm.ChargeOnce: //NOTE: nothing to do here break; default: break; } return total; }