public async Task Handle(AddHistoryCommand command) { if (await _dataAccessObject.AnyAsync(m => m.Id == command.Id)) { _logger.LogWarning("Part history {code} for {vehicleId} already added", command.PartCode, command.VehicleId); await _bus.Publish(new HistoryAddedEvent { PartCode = command.PartCode, VehicleId = command.VehicleId }); return; } _logger.LogInformation("Add part history with {code} for {vehicleId} requested by {user}", command.PartCode, command.VehicleId, _userAccessor.User?.Identity.Name); var part = new DomainModel.History(command.Id, command.PartCode, command.VehicleId); await _repository.AddAsync(part); await _bus.Publish(new HistoryAddedEvent { PartCode = command.PartCode, VehicleId = command.VehicleId }); await _bus.Reply(command.Id); }
public async Task <IActionResult> Put( string id, [FromServices] IConfiguration configuration, [FromServices] IRepository <DomainModel.History> repository) { DomainModel.History history = await repository.GetAsync(id); if (history == null) { return(NotFound()); } CloudBlobContainer historyContainer = GetHistoryContainer(configuration); CloudBlockBlob blob = historyContainer.GetBlockBlobReference(GetPhotoName(id)); blob.Properties.ContentType = Request.ContentType ?? "application/octet-stream"; await blob.UploadFromStreamAsync(Request.Body); history.PhotoUri = blob.Uri.ToString(); await repository.UpdateAsync(history); return(Created(blob.Uri, id)); }