public async Task <GetLightCommandResult> Handle(GetLightCommand command) { GetLightCommandResult result = new GetLightCommandResult(); 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) { light = await UpdateState(light); result = new GetLightCommandResult(HttpStatusCode.OK).Build <Light, GetLightCommandResult>(light, command.Fields); } else if (_lightRepository.Valid) { result = new GetLightCommandResult(HttpStatusCode.NoContent); } } else { result = new GetLightCommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }
public GetLightCommandResult Get(string lightId, [FromQuery] string fields) { GetLightCommand command = new GetLightCommand(); command.SetLightId(lightId); command.SetFields(fields); return(Execute <GetLightCommand, GetLightCommandResult>(command)); }