public EditParameterSet Map(EditRequest request) { var parameterSet = new EditParameterSet(); parameterSet.Name = request.Name; parameterSet.Description = request.Description; parameterSet.Overview = request.Overview; parameterSet.Details = request.Details; parameterSet.DriveSide = request.DriveSide; parameterSet.Berth = request.Berth; parameterSet.Year = request.Year; parameterSet.PricingPeriods = new List <EditPricingPeriodParameterSet>(); parameterSet.CurrentUser = _userRepository.GetByUsername("Application"); foreach (var editPricingPeriodRequest in request.PricingPeriods) { var editPricingPeriodParameterSet = new EditPricingPeriodParameterSet(); editPricingPeriodParameterSet.Id = editPricingPeriodRequest.Id; editPricingPeriodParameterSet.StartMonth = editPricingPeriodRequest.StartMonth; editPricingPeriodParameterSet.StartDay = editPricingPeriodRequest.StartDay; editPricingPeriodParameterSet.EndMonth = editPricingPeriodRequest.EndMonth; editPricingPeriodParameterSet.EndDay = editPricingPeriodRequest.EndDay; editPricingPeriodParameterSet.FridayToFridayRate = editPricingPeriodRequest.FridayToFridayRate; editPricingPeriodParameterSet.FridayToMondayRate = editPricingPeriodRequest.FridayToMondayRate; editPricingPeriodParameterSet.MondayToFridayRate = editPricingPeriodRequest.MondayToFridayRate; editPricingPeriodParameterSet.CurrentUser = _userRepository.GetByUsername("Application"); parameterSet.PricingPeriods.Add(editPricingPeriodParameterSet); } return(parameterSet); }
public virtual void Edit(EditParameterSet parameterSet) { var now = DateTime.Now; _name = parameterSet.Name; _description = parameterSet.Description; _overview = parameterSet.Overview; _details = parameterSet.Details; _driveSide = parameterSet.DriveSide; _berth = parameterSet.Berth; _year = parameterSet.Year; _lastModifiedBy = parameterSet.CurrentUser; _lastModifiedOn = now; foreach (var editPricingPeriodParameterSet in parameterSet.PricingPeriods) { var addEditParameterSet = new AddEditParameterSet(); addEditParameterSet.Id = editPricingPeriodParameterSet.Id; addEditParameterSet.Bus = this; addEditParameterSet.StartMonth = editPricingPeriodParameterSet.StartMonth; addEditParameterSet.StartDay = editPricingPeriodParameterSet.StartDay; addEditParameterSet.EndMonth = editPricingPeriodParameterSet.EndMonth; addEditParameterSet.EndDay = editPricingPeriodParameterSet.EndDay; addEditParameterSet.FridayToFridayRate = editPricingPeriodParameterSet.FridayToFridayRate; addEditParameterSet.FridayToMondayRate = editPricingPeriodParameterSet.FridayToMondayRate; addEditParameterSet.MondayToFridayRate = editPricingPeriodParameterSet.MondayToFridayRate; addEditParameterSet.CurrentUser = editPricingPeriodParameterSet.CurrentUser; if (_pricingPeriods.Any(x => x.Id.Value == editPricingPeriodParameterSet.Id)) { var pricingPeriod = _pricingPeriods.Single(x => x.Id.Value == editPricingPeriodParameterSet.Id); pricingPeriod.Edit(addEditParameterSet); } else { var pricingPeriod = PricingPeriod.Add(addEditParameterSet); _pricingPeriods.Add(pricingPeriod); } } }
public virtual ValidationMessageCollection ValidateEdit(EditParameterSet parameterSet) { var validationMessages = new ValidationMessageCollection(); bool overlappingPricingPeriods = false; bool daysUnmatchedByPricingPeriods = false; var newPricingPeriods = parameterSet.PricingPeriods.Select(pricingPeriod => PricingPeriod.Add(new AddEditParameterSet { StartMonth = pricingPeriod.StartMonth, StartDay = pricingPeriod.StartDay, EndMonth = pricingPeriod.EndMonth, EndDay = pricingPeriod.EndDay })); for (var date = new DateTime(2000, 1, 1); date < new DateTime(2001, 1, 1); date = date.AddDays(1)) { var matchingPeriods = newPricingPeriods.Count(pricingPeriod => pricingPeriod.ContainsDate(date)); if (matchingPeriods == 0) { daysUnmatchedByPricingPeriods = true; } if (matchingPeriods > 1) { overlappingPricingPeriods = true; } } if (daysUnmatchedByPricingPeriods) { validationMessages.AddError("Some days are not covered by pricing periods."); } if (overlappingPricingPeriods) { validationMessages.AddError("Some days are covered by more than one pricing period"); } var firstPricingPeriod = newPricingPeriods .OrderBy(x => x.StartMonth) .ThenBy(x => x.StartDay) .First(); var lastPricingPeriod = newPricingPeriods .OrderBy(x => x.StartMonth) .ThenBy(x => x.StartDay) .Last(); if (firstPricingPeriod.StartMonth != 1 || firstPricingPeriod.StartDay != 1) { validationMessages.AddError("There must be a pricing period beginning January 1st"); } if (lastPricingPeriod.EndMonth != 12 || lastPricingPeriod.EndDay != 31) { validationMessages.AddError("There must be a pricing period ending December 31st"); } return(validationMessages); }