public CommandResult Handle(UpdateLightCommand command) { CommandResult result = new CommandResult(); ObjectId lightId = new ObjectId(); if (!ObjectId.TryParse(command.LightId, out lightId)) { AddNotification(nameof(command.LightId), ENotifications.InvalidFormat); } if (Valid) { Light light = _lightRepository.Get(lightId); if (light == null && _lightRepository.Valid) { AddNotification(nameof(command.LightId), ENotifications.NotFound); } if (Valid) { PinPort pinPort = null; if (command.PinPort != null) { pinPort = new PinPort(command.PinPort); } light.Update(command.Description, pinPort); if (light.Valid) { _lightRepository.Update(light); if (_lightRepository.Valid) { result = new CommandResult(HttpStatusCode.OK); } } else { result = new CommandResult(HttpStatusCode.BadRequest, light.Notifications); } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }
public IEnumerable <Light> GetLights() { return(_lightRepository.Get()); }