public IBaseCommandResult Handle(UpdateDeviceModelCommand command) { command.Validate(); if (command.Invalid) { return(new BaseCommandResult(false, "Need to fix the errors on DeviceModel", command.Notifications)); } var manufacturer = _manufacturerRepository.GetById(command.ManufacturerId); if (manufacturer == null) { return(new BaseCommandResult(false, "Manufacturer not found", null)); } var deviceModel = _repository.GetById(command.Id); if (deviceModel == null) { return(new BaseCommandResult(false, "DeviceModel not found", null)); } deviceModel.Update(command.Description, manufacturer); _repository.Update(deviceModel); return(new BaseCommandResult(true, "User Updated with Success!", deviceModel)); }
public async Task <IActionResult> Put([FromRoute] Guid id, [FromBody] UpdateDeviceModelCommand command) { var result = _handler.Handle(command); return(await Response(result)); }