Exemple #1
0
        public IActionResult CreateTariff([FromBody] CreateTariff command)
        {
            var tariff =
                _tariffFactory.Create(new TariffFactoryInput()
            {
                Created     = DateTime.Now,
                Description = command.Description,
                TariffId    = command.TariffId,
                TariffValue = command.TariffPrice,
                ValidTo     = command.ValidTo
            });

            _tariffRepository.Add(tariff);

            return(CreatedAtRoute("GetTariff", new { TariffId = tariff.Id }, tariff));
        }
Exemple #2
0
        public void Handle(CreateTariff command)
        {
            var company = _repository.Get(command.CompanyId);

            if (command.Type == TariffType.Default)
            {
                company.CreateDefaultTariff(command.TariffId, command.Name, command.FlatRate,
                                            command.KilometricRate, command.PerMinuteRate, command.MarginOfError,
                                            command.KilometerIncluded, command.MinimumRate);
            }
            else if (command.Type == TariffType.VehicleDefault)
            {
                company.CreateDefaultVehiculeTariff(command.TariffId, command.Name, command.FlatRate,
                                                    command.KilometricRate, command.PerMinuteRate, command.MarginOfError,
                                                    command.KilometerIncluded, command.VehicleTypeId, command.MinimumRate);
            }
            else if (command.Type == TariffType.Recurring)
            {
                company.CreateRecurringTariff(command.TariffId, command.Name, command.FlatRate, command.KilometricRate,
                                              command.PerMinuteRate, command.MarginOfError,
                                              daysOfTheWeek: command.DaysOfTheWeek,
                                              kilometerIncluded: command.KilometerIncluded,
                                              startTime: command.StartTime,
                                              endTime: command.EndTime,
                                              vehicleTypeId: command.VehicleTypeId,
                                              minimumRate: command.MinimumRate);
            }
            else if (command.Type == TariffType.Day)
            {
                company.CreateDayTariff(command.TariffId, command.Name, command.FlatRate,
                                        command.KilometricRate, command.PerMinuteRate, command.MarginOfError,
                                        command.KilometerIncluded, command.StartTime, command.EndTime,
                                        command.VehicleTypeId, command.MinimumRate);
            }

            _repository.Save(company, command.Id.ToString());
        }