public CommandResult Handle(UpdateBuzzerCommand command) { CommandResult result = new CommandResult(); 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 && _buzzerRepository.Valid) { AddNotification(nameof(command.BuzzerId), ENotifications.NotFound); } if (Valid) { PinPort pinPort = null; if (command.PinPort != null) { pinPort = new PinPort(command.PinPort); } buzzer.Update(command.Description, pinPort); if (buzzer.Valid) { _buzzerRepository.Update(buzzer); if (_buzzerRepository.Valid) { result = new CommandResult(HttpStatusCode.OK); } } else { result = new CommandResult(HttpStatusCode.BadRequest, buzzer.Notifications); } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }
public CommandResult Update(string buzzerId, [FromBody] UpdateBuzzerCommand command) { if (command == null) { command = new UpdateBuzzerCommand(); } command.SetBuzzerId(buzzerId); return(Execute <UpdateBuzzerCommand, CommandResult>(command)); }