public ActionResult Init() { var basicCommand = new CreateBasicElectricityTariffProductCommand(); basicCommand.Name = "Basic electricity tariff"; basicCommand.CentkWh = 22; basicCommand.BasicCostsPerMonth = 5; var result = _handler.Handle(basicCommand); if (_handler.Invalid) { return(BadRequest(result)); } var packagedCommand = new CreatePackagedTariffProductCommand(); packagedCommand.Name = "Packaged tariff"; packagedCommand.CentkWh = 30; packagedCommand.BasicCostsPerYear = 800; packagedCommand.BasicConsumption = 4000; result = _handler.Handle(packagedCommand); if (_handler.Invalid) { return(BadRequest(result)); } return(Ok()); }
public ICommandResult Handle(CreatePackagedTariffProductCommand command) { if (Invalid) { AddNotifications(command); return(new CommandResult(false, "An error occurred, It was not possible to create the product.")); } command.Validate(); if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, "Please inform all the fields")); } // Creating new product var model = new CalculationModelPackagedTariff(command.CentkWh, command.BasicCostsPerYear, command.BasicConsumption); var product = new Product(command.Name, model); // Adding notifications AddNotifications(model); AddNotifications(product); // Verifying if is valid if (Invalid) { AddNotifications(command); return(new CommandResult(false, "An error occurred, It was not possible to create the product.")); } // Saving _repository.Save(product); // Retornar o resultado positivo return(new CommandResult(true, "Product successfuly created.")); }