Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public CommandResult Update(string lightId, [FromBody] UpdateLightCommand command)
        {
            if (command == null)
            {
                command = new UpdateLightCommand();
            }

            command.SetLightId(lightId);

            return(Execute <UpdateLightCommand, CommandResult>(command));
        }