示例#1
0
        public async Task <GetBuzzerCommandResult> Handle(GetBuzzerCommand command)
        {
            GetBuzzerCommandResult result = new GetBuzzerCommandResult();

            ObjectId buzzerId = new ObjectId();

            if (!ObjectId.TryParse(command.BuzzerId, out buzzerId))
            {
                AddNotification(nameof(command.BuzzerId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Buzzer buzzer = _buzzerRepository.Get(buzzerId);

                if (buzzer != null)
                {
                    buzzer = await UpdateState(buzzer);

                    result = new GetBuzzerCommandResult(HttpStatusCode.OK).Build <Buzzer, GetBuzzerCommandResult>(buzzer, command.Fields);
                }

                else if (_buzzerRepository.Valid)
                {
                    result = new GetBuzzerCommandResult(HttpStatusCode.NoContent);
                }
            }

            else
            {
                result = new GetBuzzerCommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
示例#2
0
        public GetBuzzerCommandResult Get(string buzzerId, [FromQuery] string fields)
        {
            GetBuzzerCommand command = new GetBuzzerCommand();

            command.SetBuzzerId(buzzerId);
            command.SetFields(fields);

            return(Execute <GetBuzzerCommand, GetBuzzerCommandResult>(command));
        }