public bool ValidateProviderData(PackageBaseData package, System.Web.WebPages.Html.ModelStateDictionary modelState) { var valid = true; PricingVariables provars = PricingVariables.FromPackageBaseData(package); foreach (var provar in provars) { if (provar.Value.Def.IsProviderVariable) { // Validation: Emit error if there is not a value or is not of the desired type if (String.IsNullOrWhiteSpace(Request[provar.Key + "-value"])) { modelState.AddError(provar.Key + "-value", LcRessources.RequiredField(provar.Value.Def.VariableLabel)); valid = false; } else if (!LcUtils.ValidateType(Request[provar.Key + "-value"], provar.Value.Def.DataType)) { modelState.AddError(provar.Key + "-value", LcRessources.InvalidFieldValue(provar.Value.Def.VariableLabel)); valid = false; } // NO Validation: Detect pricing variable 'hourly rate' to copy the value to the standard field on package // PricingVariableID:1 'hourly rate' for all positions and pricings. // We need to do this data change on validation because the 'save' part happen after the package being saved (for good reasons) if (provar.Value.PricingVariableID == 1) { package.PriceRate = Request[provar.Key + "-value"].AsDecimal(); package.PriceRateUnit = "hour"; } // Validation: Check the optional variable value properties (number, min, max) if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-numberincluded"]) && !Request[provar.Key + "-numberincluded"].IsDecimal()) { modelState.AddError(provar.Key + "-numberincluded", String.Format("Invalid number for included '{0}'", provar.Value.Def.VariableNameSingular)); valid = false; } if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-minnumberallowed"]) && !Request[provar.Key + "-minnumberallowed"].IsDecimal()) { modelState.AddError(provar.Key + "-minnumberallowed", String.Format("Invalid number for '{0}'", provar.Value.Def.MinNumberAllowedLabel)); valid = false; } if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-maxnumberallowed"]) && !Request[provar.Key + "-maxnumberallowed"].IsDecimal()) { modelState.AddError(provar.Key + "-maxnumberallowed", String.Format("Invalid number for '{0}'", provar.Value.Def.MaxNumberAllowedLabel)); valid = false; } } } return(valid); }
public void CalculateCustomerData(int customerID, PackageBaseData package, FeeRate fee, PricingModelData modelData, System.Web.WebPages.Html.ModelStateDictionary ModelState) { /* IMPORTANT: we calculate here the service duration for one session based on some custom variables for housekeeper pricing, * final price and fees are calculated in the standard code using the package Duration field, because of that * we only update package.Duration here for later complete price calculation */ // Get customer input var nbeds = Request[String.Format("bedrooms-number[{0}]", package.ID)].AsInt(); var nbaths = Request[String.Format("bathrooms-number[{0}]", package.ID)].AsInt(); // get provider rate var providerRate = GetProviderCleaningRate(package); // Apply formula, changed by the providerRate (variation from the average) var duration = ApplyFormula(nbeds, nbaths) * providerRate; // Create time object from duration, rounded to quarter-hours (15 minutes blocks) var timeDuration = ASP.LcHelpers.RoundTimeToQuarterHour(TimeSpan.FromMinutes(duration), ASP.LcHelpers.RoundingType.Up); // Create variables object with the specific data used in this calculation (will be saved later by the normal packages process) // Provider values get included in the object, something that is wanted for historic purposes on database. PricingVariables pricingvars = PricingVariables.FromPackageBaseData(package); pricingvars["BathsNumber"].Value = nbaths; pricingvars["BedsNumber"].Value = nbeds; // Change package with the information: package.Duration = timeDuration; modelData.ProviderInput = providerRate; modelData.CustomerInput = pricingvars; }
public bool ValidateProviderData(PackageBaseData package, System.Web.WebPages.Html.ModelStateDictionary modelState) { return(Request["provider-average-time"].AsFloat() > 0); }
public void CalculateCustomerData(int customerID, PackageBaseData package, FeeRate fee, PricingModelData modelData, System.Web.WebPages.Html.ModelStateDictionary ModelState) { /* IMPORTANT: we set here the service duration for one session based on the customer value (from the form), * update the hourly-price from provider variable value * and the hourly-surcharge based on the variables. * Final price and fees are calculated in the standard code using the package Duration field and HourlySurcharge field, because of that * the final price is not calculated here. */ // TOREVIEW: Needs input data validation with ModelState and check ModelState.IsValid at LcPricingModel? // Getting variables PricingVariables pricingvars = PricingVariables.FromPackageBaseData(package); TimeSpan timeDuration = TimeSpan.Zero; decimal hourlySurcharge = 0; // Iterating customer variables: foreach (var pvar in pricingvars) { if (pvar.Value.Def.IsCustomerVariable) { // Setting value from the form pvar.Value.Value = LcUtils.GetTypedValue(Request[String.Format("{0}[{1}]", pvar.Key, package.ID)], null, pvar.Value.Def.DataType); // For the 'Hours:2' customer variable, we get it form the form and set the duration with it. if (pvar.Key == "Hours") { // Create time object from duration, rounded to quarter-hours (15 minutes blocks) var duration = pvar.Value.GetValue <double>(0); timeDuration = ASP.LcHelpers.RoundTimeToQuarterHour(TimeSpan.FromHours(duration), ASP.LcHelpers.RoundingType.Up); } else { // For other variables, we calculate it using the general formula and its added to the hourly surcharge // Get the provider var, we need its values. var provar = pricingvars.GetCalculateWithVariableFor(pvar.Value); // General formula for 1 hour: (CustomerValueInputVariable - ProviderNumberIncludedVariable) * ProviderPriceVariable // EXCEPT when CustomerValueInputVariable is equal or less than ProviderNumberIncludedVariable, then is 0 decimal amount = 0; if (pvar.Value.GetValue <decimal>(0) > (provar.ProviderNumberIncluded ?? 0)) { amount = (pvar.Value.GetValue <decimal>(0) - (provar.ProviderNumberIncluded ?? 0)) * provar.GetValue <decimal>(0); } // Add to the hourly surcharge hourlySurcharge += amount; } } } // Update package data: package.Duration = timeDuration; package.HourlySurcharge = hourlySurcharge; modelData.CustomerInput = pricingvars; }
internal HtmlHelper(ModelStateDictionary modelState, ValidationHelper validationHelper) { ModelState = modelState; _validationHelper = validationHelper; }