public async Task <IActionResult> Update(TotemDto totemDto, IFormFile image, IFormFile file) { //updates totem's data var totem = await _totemService.UpdateAsync(totemDto); if (image != null) { //updates totem's image await _blobStorageService.UpdateResourceBlobAsync( new ResourceBlobDto { Id = totem.Id, Name = image.FileName, Type = Resource.TotemImage, Blob = image.OpenReadStream() }); } if (file != null) { //updates totem's image await _blobStorageService.UpdateResourceBlobAsync( new ResourceBlobDto { Id = totem.Id, Name = file.FileName, Type = Resource.TotemBlob, Blob = file.OpenReadStream() }); } return(RedirectToAction(nameof(Index))); }
public async Task <TotemDto> CreateAsync(TotemDto totemDto) { var entity = _mapper.Map <TotemDto, ExploraTotem>(totemDto); _repository.Create <ExploraTotem, int>(entity); await SaveChangesAsync(); entity.ImageUrl = $"api/totems/{entity.Id}/image-data"; entity.FileUrl = $"api/totems/{entity.Id}/file-data"; await SaveChangesAsync(); return(_mapper.Map <TotemDto>(entity)); }
public async Task <TotemDto> UpdateAsync(TotemDto totemDto) { var totem = await _repository.GetEntityByIdAsync <ExploraTotem, int>(totemDto.Id); if (totem != null) { totem.Name = totemDto.Name; totem.Description = totemDto.Description; totem.ModifiedDate = DateTime.UtcNow; _repository.Update(totem); await SaveChangesAsync(); return(_mapper.Map <TotemDto>(totem)); } return(default(TotemDto)); }